开发者

Problem with urllib

I wrote this code:

import urllib
proxies = {'http': 'http://112.65.135.54:8080/'}
opener = urllib.FancyURLopener(proxies)
r = opener.open("http://www.python.org/")
print r.read()

and when I execute it this program works fine, and send for me source code of python.org But when i use this:

import urllib
proxies = {'http': 'http://80.176.245.196:1080/'}
opener = urllib.FancyURLopener(proxies)
r = open开发者_开发问答er.open("http://www.python.org/")
print r.read()

this program does not send me the source code of python.org What am I going to do?


hehe :d i find the answer i must use "socks" instead of "http" : import urllib proxies = {'socks': 'http://80.176.245.196:1080/'} opener = urllib.FancyURLopener(proxies) r = opener.open("http://www.python.org/") print r.read()

this code works fine


Presumably, the first IP address and port points to a working proxy, while the second set does not (they're on private IPs so of course nobody else can check). So, speak with whoever handles your local network, and get the exact specs for IP and port of the HTTP proxy you're supposed to use!

Edit: aargh, the question had been edited to "mask" the IPs (now they're back and they're definitely not on private networks!) -- so the answer was based on that. Anyway, no need for digging now, as the OP has already discovered that one is a socks proxy, not an http proxy, and so of course can't be treated as the latter;-).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜