Issue
I am developing a azure function on my local with python v2. I am trying to connect my local function to a local mysql db, but I can't because I don't have function.json file.
V2 model does not use funtion.json file. Where Shall I setup that data then?
When I read doc https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-sql-input?tabs=isolated-process%2Cnodejs-v4&pivots=programming-language-python#http-trigger-get-row-by-id-from-query-string-5 , which I am trying to follow, It tells you to setup some things in function.json file. However, that file is only in python v1 programming model, but not in v2.
Solution
Thanks @Vivek Vaibhav Shandilya for clarifying "Yes, Model V2 does not have function.json. bindings are defined inside the function_app.py file."
So simply solved it using mysql-connector-python (https://pypi.org/project/mysql-connector-python/) in my function_app.py file. Here is an example of what I have added:
import mysql.connector
def execute_query(query):
connection = mysql.connector.connect(
host="localhost",
user="my_user",
password="password",
database="my_database"
)
cursor = connection.cursor()
cursor.execute(query)
result = cursor.fetchall()
cursor.close()
connection.close()
return result
Answered By - Nahuel Barbieri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.