Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
770 views
in Technique[技术] by (71.8m points)

python - How to access ODBC Driver on Azure App service

I'm trying to run a Django (3.0) app on Azure App Service in Linux, connected to an Azure SQL Database. In my staging App Service instance, this works perfectly, however, when I set up my production instance on a different Azure account, my Django app can no longer access the database.

When I hardcoded the ODBC Driver 17 into database settings, I got this error in my Oryx build logs:

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

When I switched to the non-hardcoded version suggested here, I got this error:

    'driver': sorted(pyodbc.drivers()).pop(),
IndexError: pop from empty list

How does one go about installing an ODBC Driver on Azure App Service?

EDIT: I am not using the Docker deploy option. I am deploying source code directly from Github.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have tested it and it works for me.

Open ssh to you web app and run the below command:-

enter image description here

  1. apt-get update
  1. apt-get install g++
  1. apt-get install unixodbc-dev
  1. pip install pyodbc

enter image description here

Then we can use the privacy mode, or visit the website after clearing the cache. You can try to refresh a few more times and you will find that the website is back to normal.

Previous I said you can try to use venv, after I tested, I found it doesn't need to use it. Follow my step to run the command, you webapp will be ok.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...