Crawlera:407“错误授权”错误消息

2024-06-07 04:40:43 发布

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

使用Crawlera的示例代码处理带有代理的GET请求。在

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错误的代理验证错误。我已经检查了三倍,看看API密钥是否正确。在

响应标头:

^{pr2}$

请求已更新。在

$ pip freeze |grep requests
requests==2.8.1

Tags: 代码httpsauthformathttphosturl示例
2条回答

我通过添加一个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)

如果希望保留“crawlera”方式,可以尝试升级请求客户端:

pip install requests  upgrade

我也遇到了同样的问题,你的解决方案奏效了,但在进一步搜索之后,我找到了this解决方案:

正在升级到requests客户端到2.19。。。对我有用,我可以继续使用crawlara示例脚本。在

相关问题 更多 >