Python中对HTTPS连接的400错误请求

时间:2018-08-06 06:54:13

标签: python python-3.x python-2.7

Python:3.6.5(Anaconda) 操作系统:RHEL 6.9

在代理上通过https尝试连接时,我总是遇到400错误的请求错误。但是,即使没有http和curl也可以正常工作。我已经在linux cli中导出了https_proxy和http_proxy。有人告诉我该怎么办吗?

        import requests
        session = requests.Session()
        session.get("https://pypi.python.org/simple/").content

回溯(最近通话最近一次):

File "/apps/bitech/python/lib/python3.6/site-packages/urllib3/connectionpool.py", line 595, in urlopen
self._prepare_proxy(conn)
File "/apps/bitech/python/lib/python3.6/site-packages/urllib3/connectionpool.py", line 816, in _prepare_proxy
conn.connect()
File "/apps/bitech/python/lib/python3.6/site-packages/urllib3/connection.py", line 294, in connect
self._tunnel()
File "/apps/bitech/python/lib/python3.6/http/client.py", line 919, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 400 Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/apps/bitech/python/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/apps/bitech/python/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/apps/bitech/python/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/ (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 400 Bad Request',)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/apps/bitech/python/lib/python3.6/site-packages/requests/sessions.py", line 521, in get
return self.request('GET', url, **kwargs)
File "/apps/bitech/python/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/apps/bitech/python/lib/python3.6/site-packages/requests/sessions.py", line 640, in send
history = [resp for resp in gen] if allow_redirects else []
File "/apps/bitech/python/lib/python3.6/site-packages/requests/sessions.py", line 640, in
history = [resp for resp in gen] if allow_redirects else []
File "/apps/bitech/python/lib/python3.6/site-packages/requests/sessions.py", line 218, in resolve_redirects
**adapter_kwargs
File "/apps/bitech/python/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/apps/bitech/python/lib/python3.6/site-packages/requests/adapters.py", line 502, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/ (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 400 Bad Request',)))

0 个答案:

没有答案