将 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 是否正确的三倍。
响应标头:
{
'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