1

I'm learning around Azure Functions currently & have some test scripts in Python.

Within that function I want to be able to do a post request to grab some data from elsewhere, however I can't import the requests library as I usually would in python.

Any idea where i should look to or other libraries i can use within Azure functions?

stephen.webb
  • 175
  • 2
  • 13

2 Answers2

1

I could reproduce your problem when use VS code to publish, mostly just put module in the requirements.txt it will install modules automatically however it's ignored with VS code ,suppose you are using visual studio code too.

If yes, you could have a try with Azure Functions Core Tools, Remote build and Local build both of them could publish the function successfully with the module.

More details you could refer to doc: Publishing to Azure.

Have a try with func azure functionapp publish <APP_NAME> --build local.

George Chen
  • 13,703
  • 2
  • 11
  • 26
-1

You can use the requests's api from python like this way:

import requests
import base64

pat = 'token'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii') #you can use this function to encode the token to base64 or directly encode the code to base64 and after that, use token with authorization variable

headers = {

    'Authorization': 'Basic '+authorization,
    'Content-Type': 'application/json-patch+json'
}
data = [
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": 'null',
    "value": "Test"
  }
]

response = requests.post(
    url="https://dev.azure.com/{project}/{team}/_apis/wit/workitems/$task?api-version=6.0-preview.3", json =data, headers=headers)
print(response.json()) 

#this example you can create a workitem in task, for example