首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试使用pyobdc连接Azure Application上的Flask应用程序中的Server时出错

尝试使用pyobdc连接Azure Application上的Flask应用程序中的Server时出错
EN

Stack Overflow用户
提问于 2022-10-25 19:58:18
回答 1查看 23关注 0票数 0

我正在开发一个使用Python和Flask的web应用程序。

我的应用程序使用pyobdc访问Microsoft。它在本地运行。

当我将它部署到Azure application并使用该应用程序时,当它需要访问服务器时,它会崩溃,这给了我这个错误:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

随机细节:

  • Azure Python版本: 3.8.12
  • Linux详细信息: Debian /Linux 9(拉伸)

我尝试使用我的Azure中的kudu终端手动安装它,使用这个ODBC驱动程序linux链接中的说明。但是当我尝试的时候,它告诉我sudo不是命令。(这是关于Azure限制或IT权限的问题吗?)

我还尝试将Server升级到ODBC驱动程序18,但没有成功。

我在一些地方读到,不支持ODBC,也不支持安装ODBC。

这是真的吗?有办法解决这个问题吗?

有没有其他方法将MS连接到部署在azure上的python烧瓶web应用程序?

我还检查了odbc.ini和odbcinst.ini文件在/etc中,发现它们是空的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-28 19:06:36

我解决了我的问题。

我通过dockerfile为Server安装了ODBC驱动程序17。我使用了关于如何使用ODBC17Debian版本安装found 这里的说明。但是由于一些错误,它没有完全工作,所以我稍微修改了一下。

这就是我在码头上添加的内容:

代码语言:javascript
运行
复制
#What I added to deal with the errors I was getting:
RUN apt-get update -y
RUN apt install unixodbc -y

#Installation instructions from microsoft link:
RUN su
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN exit
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools

#Checking the installation
RUN cat /etc/odbcinst.ini
        
#Create the odbc.ini file
RUN echo -e '[voip]\nDescription = whatever\nDriver      = ODBC Driver 17 for SQL Server\nServer      = whatever\nUser        = whatever\nPassword    = whatever\nPort        = whatever\nDatabase    = whatever' > odbc.ini

#Moving odbc.ini to the etc directory
RUN mv odbc.ini etc

#Checking contents of odbc.ini
RUN cat /etc/odbc.ini 

我不得不自己编辑odbc.ini,因为它是空的。但是,在运行微软指令提供的命令之后,应该填充odbcinst.ini。

etc/odbcinst.ini应该有这样的内容:

代码语言:javascript
运行
复制
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.1.1
UsageCount=1

etc/odbc.ini应该是这样的:

代码语言:javascript
运行
复制
[voip]
Description = whatever
Driver      = ODBC Driver 17 for SQL Server
Server      = whatever
User        = whatever
Password    = whatever
Port        = whatever
Database    = whatever

如果您有此问题,您将不得不自己编辑odbc.ini。但我所做的是创建一个odbc.ini文件。然后把它转移到/etc中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74199557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档