1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import urllib2 # set up authentication info authinfo = urllib2.HTTPBasicAuthHandler() authinfo.add_password(realm='PDQ Application', uri='https://mahler:8092/site-updates.py', user='klem', passwd='geheim$parole') proxy_support = urllib2.ProxyHandler({"http" : "http://ahad-haam:3128"}) # build a new opener that adds authentication and caching FTP handlers opener = urllib2.build_opener(proxy_support, authinfo, urllib2.CacheFTPHandler) # install it urllib2.install_opener(opener) f = urllib2.urlopen('http://www.python.org/') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import tornado.httpclient param = { "url" : "http://www.renjie.me/example", "proxy_host" : "proxy.renjie.me", "proxy_port" : 8080, "proxy_username" : "test", "proxy_password" : "welcome", "auth_mode" : "basic", "auth_username" : "renjie", "auth_password" : "CASwW8iJ" } http_request = tornado.httpclient.HTTPRequest(**param) http_client = tornado.httpclient.HTTPClient() try: response = http_client.fetch(http_request) print response.body except tornado.httpclient.HTTPError as e: print "Error:", e http_client.close() |