OSX El Capitan 10.11.6上忽略Python请求或Urllib2代理设置 当Python和Reals/UrLIb2库时,我认为我自己是一个高级开发人员。
最近,我使用并行机切换到运行OSX和Win10的Mac。 当使用代理选择方法运行上述任一库时,OSX会忽略自定义http请求代理设置并继续使用我的公共IP,如果我使用Win10,则不会发生这种情况 方法尝试:OSX El Capitan 10.11.6上忽略Python请求或Urllib2代理设置 当Python和Reals/UrLIb2库时,我认为我自己是一个高级开发人员。,python,macos,proxy,python-requests,Python,Macos,Proxy,Python Requests,最近,我使用并行机切换到运行OSX和Win10的Mac。 当使用代理选择方法运行上述任一库时,OSX会忽略自定义http请求代理设置并继续使用我的公共IP,如果我使用Win10,则不会发生这种情况 方法尝试: def简单请求(self): base_url=“www.whater.com” 代理服务器=”http://192.168.2.1:8080" #我使用jsonip.com作为主机来获取我的请求IP r=requests.get(r'http://jsonip.com,代理={“http
def简单请求(self):
base_url=“www.whater.com”
代理服务器=”http://192.168.2.1:8080"
#我使用jsonip.com作为主机来获取我的请求IP
r=requests.get(r'http://jsonip.com,代理={“http”:proxy})
ip=r.json()['ip']#将始终是我的公共ip
我一直在使用通过两种方式测试有效的代理:
requests.exceptions.ConnectionError:HTTPConnectionPool最大重试次数超过url
当我将无效的代理设置应用于OSX网络首选项管理器时,确实会出现此错误
我曾尝试在osx下使用代理,并使用了上面提到的两个库,得到了相同的结果
尝试过的其他解决方案:
将更改我的设置,但我必须重新启动代码才能使用它, 而将连接设置更改为整个操作系统服务并不重要 对我来说,这是一个有效的解决方案
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 199.116.113.206
send: 'GET http://jsonip.com/ HTTP/1.1\r\nHost: jsonip.com\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.11.1\r\n\r\n'
reply: 'HTTP/1.1 301 Moved Permanently\r\n'
header: Date: Thu, 12 Jan 2017 02:13:25 GMT
header: Server: nginx/1.10.0 (Ubuntu)
header: Content-Type: text/html
header: Content-Length: 194
header: Location: https://jsonip.com/
header: Keep-Alive: timeout=5, max=100
header: Connection: Keep-Alive
DEBUG:requests.packages.urllib3.connectionpool:"GET http://jsonip.com/ HTTP/1.1" 301 194
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): jsonip.com
send: 'GET / HTTP/1.1\r\nHost: jsonip.com\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.11.1\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx/1.10.0 (Ubuntu)
header: Date: Thu, 12 Jan 2017 02:13:25 GMT
header: Content-Type: application/json; charset=utf-8
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Methods: GET
header: Strict-Transport-Security: max-age=31536000;
DEBUG:requests.packages.urllib3.connectionpool:"GET / HTTP/1.1" 200 None
好吧,一个新手犯的错误
我遵循了l'l建议——简单但重要——在将所有urllib3连接记录到控制台之后,我意识到
我试图使用HTTP代理连接到HTTPS服务器,因此失败
我仍然不明白为什么代理会自动被忽略,而不会在控制台上打印异常或警告,为什么连接管理器在没有代理的情况下继续发送请求 你应该展示更多的回溯,这可能有助于缩小范围。回溯?我没有例外。Https服务器和http代理出错它工作得很好…:)