"No module named 'MySQLdb' error when deploying Django apps to the Google App Engine"

Asked 1 years ago, Updated 1 years ago, 60 views

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

I'm trying to move the Django chat bot of ↑ based on the document to which I linked it.
The last deployment to Google app engine is clogged.

■Problems you are experiencing

 python manage.py runserver

Then it works fine, but

gcloud app deploy

It appears that the deployment was successful when
If you open the specified URL in your browser, 502 Bad Gateway will be displayed.

If you look at the Google app engine log viewer, you can see

textPayload: "Traceback (most recent call last):
  File"/env/lib/python 3.7/site-packages/gunicorn/arbiter.py", line 583, inspawn_worker
    worker.init_process()
  File "/env/lib/python 3.7/site-packages/gunicorn/workers/gthread.py", line 104, init_process
    super(ThreadWorker,self).init_process()
  File"/env/lib/python 3.7/site-packages/gunicorn/workers/base.py", line 129, init_process
    self.load_wsgi()
  File"/env/lib/python 3.7/site-packages/gunicorn/workers/base.py", line 138, inload_wsgi
    self.wsgi=self.app.wsgi()
  File "/env/lib/python 3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable=self.load()
  File "/env/lib/python 3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File"/env/lib/python 3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, inload_wsgiapp
    returnutil.import_app(self.app_uri)
  File"/env/lib/python 3.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/python 3.7/site-packages/django/core/wsgi.py", line12, inget_wsgi_application
    django.setup(set_prefix=False)
  File "/env/lib/python 3.7/site-packages/django/_init__.py", line 19, setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File"/env/lib/python 3.7/site-packages/django/conf/__init__.py", line 57, in__getattr__
    self._setup(name)
  File"/env/lib/python 3.7/site-packages/django/conf/__init__.py", line 44, in_setup
    self._wrapped=Settings(settings_module)
  File"/env/lib/python 3.7/site-packages/django/conf/__init__.py", line 107, in_init__
    mod=importlib.import_module(self.SETTINGS_MODULE)
  File "/opt/python 3.7/lib/python 3.7/importlib/_init__.py", line 127, 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'" 

appears.
I can see that you are having trouble loading the MySQLdb module.
runserver works fine, but I don't know why I get errors on the GAE.

By the way, the notation on setting.py is

#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#noqa:402

and

 pip install mysqlclient

The installation was completed in .
Do I need any additional configuration to load the MySQLdb module on the GAE?
I would appreciate your advice.

■Problematic environment
·Windows 10
·Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64bit (AMD64)]:: Anaconda, Inc. on win32
·django 2.2.4
·MySQL 2nd Generation 5.7

mysql django google-app-engine

2022-09-29 22:27

1 Answers

Try doing the following:

  • If the pip contains PyMySQL (only mysqlclient is OK)
    pip uninstall PyMySQL

  • Delete the following two lines of settings.py

If the pip contains PyMySQL (only mysqlclient is OK)
pip uninstall PyMySQL

Delete the following two lines on settings.py

import pymysql#noqa:402
pymysql.install_as_MySQLdb()
  • Finally reflected in requirements.txt
    pipe freeze>requirements.txt


2022-09-29 22:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.