python'requests'包​​与代理无法正常工作

时间:2018-06-03 06:37:09

标签: python proxy python-requests

以下是我的测试代码:

import requests
url = 'https://api.ipify.org/'
proxyapi = 'http://ip.11jsq.com/index.php/api/entry?method=proxyServer.generate_api_url&packid=1&fa=0&fetch_key=&qty=1&time=1&pro=&city=&port=1&format=txt&ss=1&css=&dt=1'
proxy = {'http' : 'http://{}'.format(requests.get(proxyapi).text)}
print ('Downloading with fresh proxy.', proxy)
resp = requests.get(url, proxies = proxy_new)
print ('Fresh proxy response status.', resp.status_code)
print (resp.text)
#terminal output
Downloading with fresh proxy. {'http': 'http://49.84.152.176:30311'}
Fresh proxy response status. 200
222.68.154.34#my public ip address

没有错误消息,似乎请求lib从不应用此代理设置。 proxyapi对我在网络浏览器中检查了代理是有效的,通过访问https://api.ipify.org/,它会返回所需的代理服务器的IP地址。

我正在使用python 3.6.4并请求2.18.4。

0 个答案:

没有答案