对带有代理的GET请求使用Crawlera的示例代码。
import requests
url = "http://httpbin.org/ip"
proxy_host = "proxy.crawlera.com"
proxy_port = "8010"
proxy_auth = "<APIKEY>:" # Make sure to include ':' at the end
proxies = {
"https": "https://{}@{}:{}/".format(proxy_auth, proxy_host, proxy_port),
"http": "http://{}@{}:{}/".format(proxy_auth, proxy_host, proxy_port)
}
r = requests.get(url, proxies=proxies, verify=False)我得到了一个407坏代理Auth错误。我已经三倍地确认API_KEY是正确的。
响应头:
{
'Proxy-Connection': 'close',
'Proxy-Authenticate': 'Basic realm="Crawlera"',
'Transfer-Encoding': 'chunked',
'Connection': 'close',
'Date': 'Mon, 26 Mar 2018 11:18:05 GMT',
'X-Crawlera-Error': 'bad_proxy_auth',
'X-Crawlera-Version': '1.32.0-07c786'
}请求已经更新。
$ pip freeze |grep requests
requests==2.8.1发布于 2018-03-26 22:47:27
通过添加一个Proxy-Authorization头,我设法使它正常工作。
proxy_auth = "<APIKEY>:"
headers = {
# other headers ...
"Proxy-Authorization": 'Basic ' + base64.b64encode(proxy_auth)
}
proxies = {
"https": "https://{}:{}/".format(proxy_host, proxy_port),
"http": "http://{}:{}/".format(proxy_host, proxy_port)
}
r = requests.get(url, headers=headers, proxies=proxies, verify=False)发布于 2018-06-19 17:36:07
如果您想保留“爬行”的方式,可以尝试升级请求客户端:
pip install requests --upgrade我也遇到了同样的问题,您的解决方案成功了,但是经过进一步的搜索,我找到了这解决方案:
升级到requests客户端到2.19.为我工作,我可以继续使用Crawlera示例脚本。
https://stackoverflow.com/questions/49490364
复制相似问题