首页 > 代码库 > Python的一些常用知识

Python的一些常用知识

1、How to force urllib2 not to use a proxy

Here is an example to remove proxy settings for all requests:

proxy_handler = urllib2.ProxyHandler({})opener = urllib2.build_opener(proxy_handler)urllib2.install_opener(opener)


And here is an example for only one request:

proxy_handler = urllib2.ProxyHandler({})opener = urllib2.build_opener(proxy_handler)req = urllib2.Request(http://...)r = opener.open(req)result = r.read()

 参考网址:http://www.decalage.info/en/python/urllib2noproxy

Python的一些常用知识