0

I'm setting GitHub source ↓

https://github.com/priyankavergadia/Django-Dialogflow-GoogleVisionAPI

But I have trouble in [Deploy the app to the App Engine standard environment] phase. At a glance Deploying have been done well.But I'm trying to access webservice, so [502 Bad Gateway] appears.

  • At local environment(running python manage.py runserver), this program works well.

Please give me some advices.

My environment:

  • Windows10
  • Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
  • django 2.2.4
  • MySQL second generation 5.7
  • mysql django

I serched and tried to:

  1. install mysqlclient and uninstall PyMySQL
  2. rewrite [import ~]part in various pattern...

description in Django setting.py below

# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

# Install PyMySQL as mysqlclient/MySQLdb to use Django's mysqlclient adapter
# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers
# for more information
import MySQLdb as sql# noqa: 402

# [START db_setup]
if os.getenv('GAE_APPLICATION', None):
    # Running on production App Engine, so connect to Google Cloud SQL using
    # the unix socket at /cloudsql/<your-cloudsql-connection string>
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '/cloudsql/michatbot-250809:us-central1:polls-instance2',
            'USER': 'test',
            'PASSWORD': '',
            'NAME': 'polls',
        }
    }
else:
    # Running locally so connect to either a local MySQL instance or connect to
    # Cloud SQL via the proxy. To start the proxy via command line:

    #     $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
    #
    # See https://cloud.google.com/sql/docs/mysql-connect-proxy
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '127.0.0.1',
            'PORT': '3306',
            'NAME': 'polls',
            'USER': 'test',
            'PASSWORD': '',
        }
    }
# [END db_setup]

eroor log on Google App Engine below

   textPayload: "Traceback (most recent call last):
  File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
    super(ThreadWorker, self).init_process()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/srv/main.py", line 1, in <module>
    from mysite.wsgi import application
  File "/srv/mysite/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/env/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
    self._setup(name)
  File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 107, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/srv/mysite/settings.py", line 82, in <module>
    import MySQLdb as sql  # noqa: 402
ModuleNotFoundError: No module named 'MySQLdb'"
Tms91
  • 3,456
  • 6
  • 40
  • 74

1 Answers1

0

There are two threads where the community figured out several ways to solve this error depending on your SO and software's versions. You can refer to these threads, second one, and also to this one that addresses discussion more about connecting MySQL in Python 3 on Windows.

Make sure to follow the documentation about Python 3.7 in the GAE Standard. Also, GAE has some specific support for using Django, I'd suggest going through the Django Support documentation and Django App example.

Pranay Nanda
  • 179
  • 3
  • 21
Michael T
  • 120
  • 6
  • It`s kind of you to reply me. I think that i can't solve this probrem now. i will read documentations you told me and challenge again. Thanks! – 荒木 聖 Sep 19 '19 at 15:05