Python Forum
get request with custom header
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get request with custom header
#1
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)
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get json data by request with header? dokipo 0 1,916 Nov-06-2021, 04:51 PM
Last Post: dokipo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020