Crawlera: 407 "Bad Auth" 错误信息

Crawlera: 407 "Bad Auth" error message

将 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 Bad Proxy Auth 错误。我已经检查了三次 API_KEY 是否正确。

回应headers:

{
   '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

我设法通过添加 Proxy-Authorization header.

让它工作
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...对我有用,我可以继续使用 Crawlera 示例脚本。