简体   繁体   English

结果:失败 异常:AttributeError: 'Engine' object has no attribute 'execute' Azure Functions

[英]Result: Failure Exception: AttributeError: 'Engine' object has no attribute 'execute' Azure Functions

I am quite new to Azure Functions.我对 Azure 函数很陌生。 This code for some reason runs locally but when deployed to an Azure Function, give this error.由于某种原因,此代码在本地运行,但在部署到 Azure Function 时,会出现此错误。

from sqlalchemy import create_engine, event
import textwrap
import base64
import pandas as pd
import logging
import pyodbc

def sql_run_query(data_base,service_date):
    driver = '{ODBC Driver 17 for SQL Server}'
    server_name = **********************************
    database_name = data_base
    server='{server_name},1433'.format(server_name=server_name)
    username = **********************************
    password = **********************************
    connection_string=textwrap.dedent('''Driver={driver};Server={server};Database={database};Uid={username};Pwd={password};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;'''.format(driver=driver,server=server,database=database_name,username=username,password=password))
    engine = create_engine('mssql+pyodbc:///?odbc_connect='+connection_string)
    #engine =create_sql_engine(data_base)
    engine.execute('declare @service_date_var as varchar(100) = '+service_date+'delete from [dbo].[performance] where service_date = @service_date_var')
    logging.info(f"query in {data_base} run succesfully")
    print(f"query in {data_base} run succesfully")

Result: Failure Exception: AttributeError: 'Engine' object has no attribute 'execute' Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 452, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 718, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/BlobTrigger2/ init .py", line 40, in main sql_run_query('kad_smc',dte) File "/home/site/wwwroot/sql_uploader/sql_uploader.py", line 74, in sql_run_query engine.execute('''结果:失败异常:AttributeError:'引擎'object 没有属性'执行'堆栈:文件“/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py”,第 452 行,在 _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self .kwargs) 文件“/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py”,第 718 行,在 _run_sync_func 返回 ExtensionManager.get_sync_invocation_wrapper(上下文,文件“/azure-functions-host/ workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py”,第 215 行,在 _raw_invocation_wrapper result = function(**args) 文件“/home/site/wwwroot/BlobTrigger2/ init .py”,第 40 行,在主 sql_run_query('kad_smc',dte) 文件“/home/site/wwwroot/sql_uploader/sql_uploader.py”,第 74 行,在 sql_run_query engine.execute('''

Can someone explain the reason for this and a possible fix?有人可以解释这个的原因和可能的解决方法吗?

Thanks!谢谢!

The deprecated execute method of engine has been removed in SQLAlchemy 2.0. SQLAlchemy 2.0 中移除了engine 不推荐使用execute方法。 You need to ensure that you are running the same version of SQLAlchemy in both environments and consider migrating to v2.0.您需要确保在两个环境中运行相同版本的 SQLAlchemy 并考虑 迁移到 v2.0。

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

相关问题 AttributeError: 'CollectionReference' 对象没有属性 'doc' - AttributeError: 'CollectionReference' object has no attribute 'doc' AttributeError: 'dict' 对象没有属性 'Instance' python - AttributeError: 'dict' object has no attribute 'Instance' python AttributeError: 'NoneType' object 在 googletrans 中没有属性 'group' - AttributeError: 'NoneType' object has no attribute 'group' in googletrans AttributeError: 'DataFrame' object 没有属性 'randomSplit' - AttributeError: 'DataFrame' object has no attribute 'randomSplit' AttributeError: 'function' object 在 Azure Databricks 中使用修复作业时没有属性 'name' - AttributeError: 'function' object has no attribute 'name' when using repair job in Azure Databricks AttributeError: 'DataFrame' object 没有属性 'Join' - AttributeError: 'DataFrame' object has no attribute 'Join' AttributeError: 'str' object 没有属性 'request' - googletrans - AttributeError: 'str' object has no attribute 'request' - googletrans AttributeError: 'dict' object 没有属性 'Credentials' - AttributeError: 'dict' object has no attribute 'Credentials' AttributeError: 'NoneType' object 没有属性 'get' 尽管字典已满 - AttributeError: 'NoneType' object has no attribute 'get' despite dictionary being full AttributeError: 'CloudSchedulerClient' object 没有属性 'location_path' - AttributeError: 'CloudSchedulerClient' object has no attribute 'location_path'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM