2016-09-14 204 views
0

我在閱讀某些網址時遇到了一些問題。Python:urllib2.URLError:<urlopen錯誤[Errno 10060]

我嘗試使用回答這個問題Using an HTTP PROXY - Python,但它並沒有幫助,我得到一個錯誤urllib2.URLError: <urlopen error [Errno 10060]

我有網址

yandex.ru/search?text=авито&lr=47 
yandex.ru/search?text=цветок%20киддиленд%20музыкальный&lr=47 
dns-shop.ru/product/c7bf1138670f3361/rul-hori-racing-wheel 
dns-shop.ru/product/c7bf1138670f3361/rul-hori-racing-wheel#opinion 
kaluga.onlinetrade.ru/catalogue/ruli_dgoystiki_geympadi-c31/hori/reviews/rul_hori_racing_wheel_controller_ps_4_ps4_020e_acps440-274260.html 
kazan.onlinetrade.ru/catalogue/ruli_dgoystiki_geympadi-c31/hori/reviews/rul_hori_racing_wheel_controller_xboxone_xbox_005u_acxone34-274261.html 
ebay.com 

列表和代碼看起來像

for url in urls: 
    proxy = urllib2.ProxyHandler({"http":"http://61.233.25.166:80"}) 
    opener = urllib2.build_opener(proxy) 
    urllib2.install_opener(opener) 
    try: 
     html = urllib2.urlopen(url).read() 
    except ValueError or urllib2: 
     url = 'http://www.' + url 
     html = urllib2.urlopen(url).read() 

另外我試了

s = requests.Session() 
s.proxies = {"http": "http://61.233.25.166:80"} 

for url in urls: 
    url = 'http://www.' + url 
    r = s.get(url) 
    print(r.text) 

,並返回我

requests.exceptions.ProxyError: HTTPConnectionPool(host='61.233.25.166', port=80): Max retries exceeded with url: http://www.yandex.ru/search?text=%D0%B8%D0%B3%D1%80%D1%83%D1%88%D0%BA%D0%B0%20%22%D0%B2%D0%B5%D1%81%D0%B5%D0%BB%D0%B0%D1%8F%20%D0%B3%D1%83%D1%81%D0%B5%D0%BD%D0%B8%D1%86%D0%B0%22%20keenway%20%D0%BE%D1%82%D0%B7%D1%8B%D0%B2%D1%8B&lr=47 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x047D1090>: Failed to establish a new connection: [Errno 10060] \xcf\xee\xef\xfb\xf2\xea\xe0 \xf3\xf1\xf2\xe0\xed\xee\xe2\xe8\xf2\xfc \xf1\xee\xe5\xe4\xe8\xed\xe5\xed\xe8\xe5 \xe1\xfb\xeb\xe0 \xe1\xe5\xe7\xf3\xf1\xef\xe5\xf8\xed\xee\xe9, \xf2.\xea. \xee\xf2 \xe4\xf0\xf3\xe3\xee\xe3\xee \xea\xee\xec\xef\xfc\xfe\xf2\xe5\xf0\xe0 \xe7\xe0 \xf2\xf0\xe5\xe1\xf3\xe5\xec\xee\xe5 \xe2\xf0\xe5\xec\xff \xed\xe5 \xef\xee\xeb\xf3\xf7\xe5\xed \xed\xf3\xe6\xed\xfb\xe9 \xee\xf2\xea\xeb\xe8\xea, \xe8\xeb\xe8 \xe1\xfb\xeb\xee \xf0\xe0\xe7\xee\xf0\xe2\xe0\xed\xee \xf3\xe6\xe5 \xf3\xf1\xf2\xe0\xed\xee\xe2\xeb\xe5\xed\xed\xee\xe5 \xf1\xee\xe5\xe4\xe8\xed\xe5\xed\xe8\xe5 \xe8\xe7-',))) 

哪裏的錯誤?

+0

那麼它說,在由ProxyError導致該錯誤消息'('無法連接到proxy.''和代理返回'時間現在超過'ping'.. –

+0

@BarisDemiray我已經嘗試過這種方式來解決我的問題。我也嘗試'urllib2'和現在'proxy_info = {'012'' , 'host':「proxyaddress」, 'port':8080 } proxy_supp ort = urllib2.ProxyHandler({「http」:「http://%(user)s:%(pass)s @%(host)s:%(port)d」%proxy_info}) opener = urllib2.build_opener (proxy_support,urllib2.HTTPHandler)''但它返回我'urllib2.URLError:'。我無法理解,哪裏出現錯誤:在代理中,我指定或在類型的網址? –

回答

0

一些代理不起作用。 我用urllib代替urllib2

for url in urls: 
    proxies = {'http': 'http://109.172.106.3:9999', 'http': 'http://62.113.208.183:3128', 'http': 'http://178.22.148.122:3129', 'http': 'http://217.17.46.162:3128'} 
    url = 'http://www.' + url 
    html = urllib.urlopen(url, proxies=proxies).read() 

它爲我的作品

相關問題