azure-function-pyodbc-mi's People
azure-function-pyodbc-mi's Issues
Exception: Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")
Hi @kevin808
Thanks for the repo. I tried to follow the code to setup the azure function app to query from azure sql database. However I received driver not found error at pyodbc.connect. Do we also have to attach the drivers to Azure Function app?
Exception: Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")
Python Azure Function and Azure SQL INSERTS
Hello,
I read your blog post about "How to connect Azure SQL database from Python Function App using managed identity or access token". I was able to SELECT *
from an Azure SQL table from my local machine.
I'm trying to adapt the code to INSERT
rows but running an error that I can't troubleshoot. Hoping you can help.
Scenario:
- Timer-trigged Azure Function ("news-agg-dev")
- Python runtime
Error:
- Initially:
[2021-12-17T06:40:01.498Z] Executed 'Functions.news-agg-dev' (Failed, Id=9e7f2a2c-7693-4f2c-8c2b-e48cf64f7e75, Duration=1482ms)
[2021-12-17T06:40:01.501Z] System.Private.CoreLib: Exception while executing function: Functions.news-agg-dev. System.Private.CoreLib: py exited with code -1073741819
.
- Then after a while:
[2021-12-17T06:45:01.492Z] Exceeded language worker restart retry count for runtime:python. Shutting down and proactively recycling the Functions Host to recover
Code:
- Python function hits some websites, creates some data
def get_xml_file(bsoup_obj, source):
xml = bsoup_obj.find('channel')
data = {
"source": source,
"pubDate": xml.find('pubDate').text,
"xml_doc": bsoup_obj,
"xml_raw": bsoup_obj,
"created": datetime.now()
}
return data
- Creates an Azure SQL connection (per your blog); I know this works
def get_sql_connection():
server = 'sqlsrv.database.windows.net'
database = 'sqldb'
driver= '{ODBC Driver 17 for SQL Server}'
db_token = '<db_token_here>'
conn_string = 'DRIVER='+driver+';SERVER='+server+';DATABASE='+database
if os.getenv('MSI_TOKEN'):
conn = pyodbc.connect(conn_string+';Authentication=ActiveDirectoryMsi')
return conn
else:
SQL_COPT_SS_ACCESS_TOKEN = 1256
exptoken = b''
for i in bytes(db_token, 'UTF-8'):
exptoken += bytes({i})
exptoken += bytes(1)
tokenstruct = struct.pack('=i', len(exptoken)) + exptoken
conn = pyodbc.connect(conn_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: tokenstruct})
return conn
- Writes data to Azure SQL per this blob here (sort of)
def write_sql_data(conn, package):
cursor = conn.cursor()
query = cursor.execute(f'INSERT INTO dbo.NEWS_XML (source, pubDate, xml_doc, xml_raw, created) VALUES (?,?,?,?,?)',
package['source'], package['pubDate'], package['xml_doc'], package['xml_raw'], package['created'])
conn.commit()
return query
This is where the error pops up. Any help you could provide would be so appreciated.
Thank you!
Python exited with code 139
Got this error:
System.Private.CoreLib: Exception while executing function: Functions.HttpTrigger. System.Private.CoreLib: python3 exited with code 139 (0x8B). .
When code is placed outside of main, it works well but when inside main I got this issue.
I tried with several OS (Ubuntu, Debian) and several versions of Python (3?7, 3.8 and 3.9)
Still same issue.... need some help please
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.