如何在python 3中将代理添加到urlib.request.Request命令?

时间:2018-06-28 12:39:56

标签: python-3.x proxy urllib

我正在尝试使用urllib.request模块从网上获取图像。

我的代码

import urllib.request as ulib

url_a = 'https://www.google.com/search?ei=1m7NWePfFYaGmQG51q7IBg&hl=en&q={}'
url_b = '\&tbm=isch&ved=0ahUKEwjjovnD7sjWAhUGQyYKHTmrC2kQuT0I7gEoAQ&start={}'
url_c = '\&yv=2&vet=10ahUKEwjjovnD7sjWAhUGQyYKHTmrC2kQuT0I7gEoAQ.1m7NWePfFYaGmQG51q7IBg'
url_d = '\.i&ijn=1&asearch=ichunk&async=_id:rg_s,_pms:s'
url_base = ''.join((url_a, url_b, url_c, url_d))

search_name = "pikachu"

url = url_base.format(search_name, 0)
request = ulib.Request(url, None, headers=headers)

收到此错误

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

但是我在公司防火墙后面。那么如何将代理添加到urllib.request.Request?

0 个答案:

没有答案