Python Proxy Test

From Federal Burro of Information
Revision as of 18:04, 29 May 2017 by David (talk | contribs)
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('XXX:8080')

username = "s-scalarcloudmgt"
password = "Sc@lar2016!"

userAndPass = b64encode(b"s-scalarcloudmgt:Sc@lar2016!").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()