Proxy basic.py
Revision as of 17:33, 29 April 2009 by PeterHarding (talk | contribs) (Created page with '=Script= <pre> $ cat proxy_basic.py #!/usr/bin/env python # # # #------------------------------------------------------------------------------- import sys import base64 impor...')
Script
$ cat proxy_basic.py #!/usr/bin/env python # # # #------------------------------------------------------------------------------- import sys import base64 import httplib import urllib2 #------------------------------------------------------------------------------- def do(): proxy_support = urllib2.ProxyHandler({"http":"http://proxy:8080"}) http_support = urllib2.HTTPHandler() opener = urllib2.build_opener(proxy_support, http_support) urllib2.install_opener(opener) connf = urllib2.urlopen('http://www.python.org/') auth = "Basic " + base64.encodestring("xxx:xxx") conn.putheader('Proxy-Authorization', auth) conn.endheaders() #errcode, errmsg, headers = conn.getresponse() rc = conn.getresponse() # print errcode # print errmsg # print headers # f = conn.getfile() # for line in f.readlines(): # print line # rc = conn.getresponse() print rc.__dict__ print rc.status, rc.reason print rc.msg data = rc.read() # print data conn.close() #------------------------------------------------------------------------------- def main(args): do() #------------------------------------------------------------------------------- if __name__ == "__main__": main(sys.argv[1:]) #-------------------------------------------------------------------------------