简体   繁体   English

Python3 SQLAlchemy Azure Function '_mysql' 未定义

[英]Python3 SQLAlchemy Azure Function '_mysql' is not defined

I'm trying to create some Python3 Azure MySQL jobs in azure functions using SQL Alchemy.我正在尝试使用 azure 函数在 azure 函数中创建一些 Python3 Azure MySQL 作业,使用 Z9778840A0100CB30BA2Z8Alchem.

Function runs locally with func start without a problem. Function 在本地运行func start没有问题。
It's in fresh venv, on fresh Linux VM to exclude any possible package dependencies.它在新的 venv 中,在新的 Linux VM 上,以排除任何可能的 package 依赖项。
Deploying to Azure via func azure functionapp publish {app_name} --build remote without any problems.通过func azure functionapp publish {app_name} --build remote部署到 Azure 没有任何问题。 But upon calling the function I'm getting:但是在调用 function 我得到:
"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.似乎未安装 MySQLdb 模块,但我的 requirements.txt 包含mysqlclient==2.0.1并且安装正确。 Even weirder, it works great when I'm running the function locally.更奇怪的是,当我在本地运行 function 时效果很好。

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(...) mysql+pymysql://mysqladmin(...)

I think it's a problem with mysqlclient.我认为这是mysqlclient的问题。

Link below may helpful, be sure that MySQL development headers and libraries are installed https://pypi.org/project/mysqlclient/下面的链接可能会有所帮助,请确保安装了 MySQL 开发头文件和库https://pypi.org/project/mysqlclient/

If everything is done and problem still exits, you can add the path of your mysql's library into LD_LIBRARY_PATH如果一切都完成并且问题仍然存在,您可以将 mysql 库的路径添加到 LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/path/to/mysql/lib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM