IOError:[Errno url error]http的无效代理:“xxx.xxx.xxx.xxx”

2024-06-17 10:36:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我的剧本有些问题。 它应该通过一个代理打开一个网站,但我总是会遇到这个错误,我试图用几个代理。。。

可能是什么?

Traceback (most recent call last):
  File "C:\Users\Shady\Desktop\ptzplace.3.0 - Copy.py", line 43, in <module>
    h = urllib.urlopen(website, proxies = {'http': proxy})
  File "C:\Python26\lib\urllib.py", line 86, in urlopen
    return opener.open(url)
  File "C:\Python26\lib\urllib.py", line 200, in open
    return self.open_unknown_proxy(proxy, fullurl, data)
  File "C:\Python26\lib\urllib.py", line 219, in open_unknown_proxy
    raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
IOError: [Errno url error] invalid proxy for http: 'xxx.xxx.xxx.xxx'

剧本是这样的

proxylist = ['79.174.195.84:80',
             '79.174.195.82:80',
             '80.233.184.227:8080',
             '79.174.195.80:80',
             '80.233.184.226:8080',
             '79.174.33.95:3128']
for proxy in proxylist:
            h = urllib.urlopen(website, proxies = {'http': proxy})

Tags: inpyhttpurlforliblineopen
3条回答

我和你的proxylist一起尝试下一个代码,但是它太长了,所以我得到了其他代理:p

import urllib
website = 'http://www.google.com/'
proxylist = ('http://75.101.215.123:9090', 'http://94.198.47.6:3128')
connlist = (urllib.urlopen(website, proxies = {'http': proxy}) for proxy in proxylist)
for conn in connlist:
    print conn.read()
    conn.close()

我相信您需要在每个代理之前使用http模式标识符:

proxylist = ['http://79.174.195.84:80',... 'http://79.174.33.95:3128'] 

尝试urllib2.urlopen,而不是urllib.urlopen。我曾经遇到过这样的情况:代理服务器上的urllib.urlopen阻塞,但是urllib2.urlopen可以很好地打开它。

相关问题 更多 >