Hello everyone,
I am encountering an issue while deploying a Flask-based chatbot application to Google Cloud. The application runs perfectly fine locally but throws an ImportError when deployed to Google Cloud.
Environment:
Error Log: The error I am encountering is as follows:
2023-08-22 01:53:48 default[20230822t035216] "GET /favicon.ico HTTP/1.1" 500
2023-08-22 01:53:48 default[20230822t035216] Traceback (most recent call last): File "main.py", line 2, in <module> from flask import Flask, request, jsonify, render_template File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/__init__.py", line 19, in <module> from . import json File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/json/__init__.py", line 15, in <module> from itsdangerous import json as _json ImportError: cannot import name 'json' from 'itsdangerous' (/layers/google.python.pip/pip/lib/python3.7/site-packages/itsdangerous/__init__.py)
Files:
main.py: Contains the main code for the chatbot.
index.html: HTML file for rendering the interface.
app.yaml:
runtime: python311
entrypoint: python main.py
env_variables:
OPENAI_API_KEY: 'sk-CODE'
requirements.txt:
aiofiles==23.2.1Attempts to Resolve:
Unfortunately, none of the above steps resolved the issue. It seems that neither the dependency nor Python get updated.
Request for Help: I would greatly appreciate any insights or suggestions on how to resolve this ImportError. If anyone has encountered a similar issue or knows what might be causing this problem, please share your thoughts. I´m very new to programming in general so I apologize in advance if this is some very obvious error.
Thank you in advance for your assistance!
Best regards, Noah
Solved! Go to Solution.
When you say it works locally, did you run it using dev_appserver.py? If you didn't, then you've bypassed app.yaml
Remove 'entrypoint: python main.py' or replace it with entrypoint: gunicorn -b :$PORT main:app and see if that solves your problem
When you say it works locally, did you run it using dev_appserver.py? If you didn't, then you've bypassed app.yaml
Remove 'entrypoint: python main.py' or replace it with entrypoint: gunicorn -b :$PORT main:app and see if that solves your problem
I have no idea why, but this works perfectly. Thank you so much!