Movatterモバイル変換


[0]ホーム

URL:


using httplib, urllib with proxy authentication

Paul Moorepaul.moore at atosorigin.com
Tue Apr 10 08:24:45 EDT 2001


Jeremy Lamplough <jeremy.lamplough at motorola.com> writes:> Is it possible to use these libraries with proxies that require password> authentication?  (I'm currently using python 1.5.2).  Do I need to upgrade?You need to use urllib2, and Python 2.1 (earlier versions have bugs -the 2.1 version as of today (beta 2) still has a bug, but I havereported it, along with a fix, so I hope it will be fixed in therelease).Sample code:----import urllib2proxy_info = {    'user' : 'username',    'pass' : 'password',    'host' : "proxy.name.com",    'port' : 80 # or 8080 or whatever} # build a new opener that uses a proxy requiring authorizationproxy_support = urllib2.ProxyHandler({"http" :                "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) # install iturllib2.install_opener(opener) f = urllib2.urlopen('http://www.python.org/')print f.headersprint f.read()----Paul.


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp