code_junkie

How do I send a custom header with urllib2 in a HTTP Request?

Nov 13th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. import urllib2
  2. request = urllib2.Request("http://www.google.com", headers={"Accept" : "text/html"})
  3. contents = urllib2.urlopen(request).read()
  4.  
  5. import urllib2
  6. contents = urllib2.Request("http://www.google.com", headers={"Accept" : "text/html"}).Read()
Add Comment
Please, Sign In to add comment