Python Forum

Full Version: get request with custom header
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

I have an assignment where I need to write a script with a custom header with a x-api-key within a range of 5500-5600 to get a file. As it stands I don't even know if I set my variables or parameters correctly and whenever I've tried to run a loop to cycle it just doesn't run it. Anyone mind helping me and explaining what I am doing wrong or if I am even in the ballpark?

 
import urllib2
x = 5558
customheader = {"x-api-key" : str(x)}
url = "127.0.0.1:8082"
request = urllib2.Request(url,"",customheader)
response = urllib2.urlopen(request)
html = response.read
print(html)
Hi,

general advise: when you have to do requests, use the requests module. It's THE standard, although it's not part of the standard lib.

requests is also very well documented.

Regards, noisefloor