2

I am trying to access the Azure Kudu Web API interface to get historical information about my WebJobs. The URL is https://myfakewebappname.scm.azurewebsites.net/api/triggeredwebjobs/HubSpot/history

This works just fine in a browser with a one time (first time you login) user and password authentication.

When I call it with a python script using the requests library, I get a 401 response code and 'WWW-Authenticate': 'Basic realm="site"'. I then send another request:

resp = requests.get('https://myfakewebappname.scm.azurewebsites.net/api/triggeredwebjobs/HubSpot/history', auth=('actualuser', 'actualpassword')). I use the user and Password that work using my browser.

I get the same 401 response code again with the same response.headers. What am I doing wrong?

1
  • Worked like a charm!! Thank you!! Commented May 5, 2021 at 16:59

1 Answer 1

2

The Authentication of the WebJobs Kudu API is via basic auth, to call the API successfully in python, please follow the steps below.

1.Navigate to the Azure portal -> your web app which has the webjob -> click Get publish profile.

enter image description here

2.Open the downloaded file with the format joyweb11.PublishSettings in step 1, note down the userName and userPWD in this file.

3.Then use the code below, replace the value of username and password with the values in step 2, also replace the webapp name in the url with yours, it works fine on my side.

import requests
from base64 import b64encode

username = '$joyweb11'
password = '7pWclexxxxxJlHwoLRwtrneE'
base64AuthInfo = b64encode((username+':'+password).encode('ascii')).decode('ascii')

url = 'https://joyweb11.scm.azurewebsites.net/api/triggeredwebjobs/HubSpot/history'
headers = {'Authorization': 'Basic ' + base64AuthInfo}

response = requests.get(url=url, headers=headers)
print(response.status_code)
print(response.text)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Worked like a charm!!
Thanks!. I spent about 2 hours trying to authenticate using my Microsoft username and password, and didn't understand why I was keep getting 401 Unauthorized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.