2

Is it possible to invoke a webjob from python?
I currently have a web app and webjob on azure. My webjob is set to triggered/manual and want to run it from python code whenever user does a specific action.
something like this from c#:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://<web appname>.scm.azurewebsites.net/api/triggeredwebjobs/<web job name>/run"); request.Method = "POST"; var byteArray = Encoding.ASCII.GetBytes("user:password"); request.Headers.Add("Authorization", "Basic "+ Convert.ToBase64String(byteArray)); request.ContentLength = 0; 

I did some research and I saw one post that suggested to use azure-sdk-for-python. But I'm not sure if that was any help as far as "triggering the webjob".

1

1 Answer 1

1

If you need simply to post a request to the azure, you can use a httplib (http.client in Python 3) like this:

import base64, httplib headers = {"Authorization": "Basic " + base64.b64encode("user:password")} conn = httplib.HTTPConnection("https://<web appname>.scm.azurewebsites.net/api/triggeredwebjobs/<web job name>/run") conn.request("POST", "", "", headers) response = conn.getresponse() print response.status, response.reason 

If you need some more complicated, you better investigate the azure-sdk-for-python package, but I can't see there anything about the webjobs right now.

This works with postman: enter image description here

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

9 Comments

Thank you for the answer. After doing more research i found that webjob can be indeed invoked by post call. it does work using postman but doesnt work with the code similar to the one you posted. Im thinking it could be related to syntax.
The code above is for Python 2, for the Python 3 it do slightly differ
the code is fine, i am using python3 and had to modify it with http.client and some other minor changes. It runs without errors just does not do anything (does not start the webjob). I can post the screenshot of postman and my code for better understanding.
Maybe you need different headers
I added the screenshot of the postman post call that works maybe you can give me a further help.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.