Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

HTTP Request With Custom Headers using Python

As you will hopefully already know by now we added the ability to use Python code a while back in Macro Scheduler 14.2.

A customer recently had a need to retrieve some data from a web service which requires some custom authentication headers to be sent with the Request.

It’s really easy to do this using Python. Here’s a made-up example:

/*
python_code:

import urllib2

custom_headers={"X-Custom-Application-Id" : "4020c4b37ead0a834c0010a9",
                "X-Custom-REST-API-Key": "49eade9c-d70a-4d3d-b552-4bd9f05966fc"}
url="https://api.custom.com/v1/objects/object_1/things"

request = urllib2.Request(url, headers=custom_headers)
contents = urllib2.urlopen(request).read()
*/

//Load the Python code to a variable
LabelToVar>python_code,pcode

//Run the code and request the value of the contents variable ...
PYExec>pcode,output,contents

//content of request is now in "contents" variable.

For more on Python in Macro Scheduler see here and here.

No related posts.



This post first appeared on Marcus' Macro Blog - Windows Macro And Windows Au, please read the originial post: here

Share the post

HTTP Request With Custom Headers using Python

×

Subscribe to Marcus' Macro Blog - Windows Macro And Windows Au

Get updates delivered right to your inbox!

Thank you for your subscription

×