Reputation: 1070
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".
Upvotes: 2
Views: 667
Reputation: 28355
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.
Upvotes: 1