Python Proxy Test

From Federal Burro of Information
Revision as of 16:38, 29 May 2017 by David (talk | contribs) (Created page with "<pre> #!/usr/bin/env python from base64 import b64encode import httplib import pprint pp = pprint.PrettyPrinter(indent=4) c = httplib.HTTPConnection('IPADDRESS:8080') userA...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
#!/usr/bin/env python

from base64 import b64encode
import httplib
import pprint

pp = pprint.PrettyPrinter(indent=4)
c = httplib.HTTPConnection('IPADDRESS:8080')

userAndPass = b64encode(b"username:password").decode("ascii")
print userAndPass
# headers = { 'Authorization' : 'Basic %s' %  userAndPass }
# pp.pprint(headers)

#then connect
# c.request('GET', '/', headers=headers)
c.request('GET', '/')

#get the response back
res = c.getresponse()

print "read()"
pp.pprint(res.read())
print ""
print "headers"
pp.pprint(res.getheaders())
print ""
print "status"
pp.pprint(res.status)
print ""
print "reason"
pp.pprint(res.reason)

pp.pprint(res)

# at this point you could check the status etc
# this gets the page text
data = res.read()