I'm trying to create some Python3 Azure MySQL jobs in azure functions using SQL Alchemy.
Function runs locally with func start without a problem.
It's in fresh venv, on fresh Linux VM to exclude any possible package dependencies.
Deploying to Azure via func azure functionapp publish {app_name} --build remote without any problems.
But upon calling the function I'm getting:
"name '_mysql' is not defined"
It seems like the MySQLdb module is not installed, but my requirements.txt contains
mysqlclient==2.0.1 and it's installing properly. Even weirder, it works great when I'm running the function locally.
This is the full error, sorry for the formatting:
Result: Failure Exception: NameError: name '_mysql' is not defined Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 262, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/site/wwwroot/vm/__init__.py", line 4, in <module> from __app__.vm.get_vm import insert_vms File "/home/site/wwwroot/vm/get_vm.py", line 3, in <module> from __app__.shared.db.models import VM File "/home/site/wwwroot/shared/db/models.py", line 3, in <module> from __app__.shared.db.base import Base, engine File "/home/site/wwwroot/shared/db/base.py", line 12, in <module> if not database_exists(url): File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy_utils/functions/database.py", line 462, in database_exists engine = sa.create_engine(url) File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine return strategy.create(*args, **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy/engine/strategies.py", line 87, in create dbapi = dialect_cls.dbapi(**dbapi_args) File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi return __import__("MySQLdb") File "/home/site/wwwroot/.python_packages/lib/site-packages/MySQLdb/__init__.py", line 24, in <module> version_info, _mysql.version_info, _mysql.__file__
Ok, this was my error from the beginning - I've forgot to put the driver in the connection string for the DB - ex. mysql+pymysql://mysqladmin(...)
Python3 SQLAlchemy Azure Function '_mysql' is not defined