我正在尝试使用TM1 REST API和Python请求运行get请求,但是收到ConnectionResetError / MaxRetryError / ProxyError。这是我的代码:
headers = {'Accept' : 'application/json; charset=utf-8',
'Content-Type': 'text/plain; charset=utf-8'
}
login = b64encode(str.encode("{}:{}:{}".format(user, password, namespace))).decode("ascii")
headers['Authorization'] = 'CAMNamespace {}'.format(login)
s = requests.Session()
r = s.get(url+query, headers=headers, proxies=urllib.request.getproxies())
我已尝试使用代理身份验证/无身份验证/无代理的get请求但我得到相同的3个错误。
作为参考,相同的网址是https,适用于JavaScript / jQuery:
function updateTable(){
$.ajax({
async:false,
headers: {
'Accept' : 'application/json; charset=utf-8',
'Content-Type': 'text/plain; charset=utf-8',
'Authorization' : 'CAMNamespace ' + btoa('username' + ':' + 'password' + ':' + 'namespace')
},
url: 'url_is_here',
success: function(data){data_is_here}
}
这是TraceBack:
---------------------------------------------------------------------------
ConnectionResetError Traceback (most recent call last)
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, **response_kw)
571 if is_new_proxy_conn:
--> 572 self._prepare_proxy(conn)
573
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py in _prepare_proxy(self, conn)
779
--> 780 conn.connect()
781
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connection.py in connect(self)
288 server_hostname=hostname,
--> 289 ssl_version=resolved_ssl_version)
290
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\util\ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir)
307 if HAS_SNI: # Platform-specific: OpenSSL with enabled SNI
--> 308 return context.wrap_socket(sock, server_hostname=server_hostname)
309
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
376 server_hostname=server_hostname,
--> 377 _context=self)
378
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\ssl.py in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context)
751 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 752 self.do_handshake()
753
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\ssl.py in do_handshake(self, block)
987 self.settimeout(None)
--> 988 self._sslobj.do_handshake()
989 finally:
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\ssl.py in do_handshake(self)
632 """Start the SSL/TLS handshake."""
--> 633 self._sslobj.do_handshake()
634 if self.context.check_hostname:
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
MaxRetryError Traceback (most recent call last)
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
402 retries=self.max_retries,
--> 403 timeout=timeout
404 )
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, **response_kw)
622 retries = retries.increment(method, url, error=e, _pool=self,
--> 623 _stacktrace=sys.exc_info()[2])
624 retries.sleep()
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
280 if new_retry.is_exhausted():
--> 281 raise MaxRetryError(_pool, url, error or ResponseError(cause))
282
MaxRetryError: HTTPSConnectionPool(host='ip', port=49003): Max retries exceeded with url: /api/v1/Threads (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)))
During handling of the above exception, another exception occurred:
ProxyError Traceback (most recent call last)
<ipython-input-36-0d70f21b1422> in <module>()
1 s = requests.Session()
----> 2 r = s.get(url+query, headers=headers)
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py in get(self, url, **kwargs)
485
486 kwargs.setdefault('allow_redirects', True)
--> 487 return self.request('GET', url, **kwargs)
488
489 def options(self, url, **kwargs):
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
473 }
474 send_kwargs.update(settings)
--> 475 resp = self.send(prep, **send_kwargs)
476
477 return resp
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
583
584 # Send the request
--> 585 r = adapter.send(request, **kwargs)
586
587 # Total elapsed time of the request (approximately)
C:\Users\vmora\AppData\Local\Continuum\Anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
463
464 if isinstance(e.reason, _ProxyError):
--> 465 raise ProxyError(e, request=request)
466
467 raise ConnectionError(e, request=request)
ProxyError: HTTPSConnectionPool(host='ip', port=49003): Max retries exceeded with url: /api/v1/Threads (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)))
答案 0 :(得分:0)
有几个人帮我解决了我的问题。我在环境变量中设置的http和https代理导致了这个问题。我删除了它们/重新启动/然后能够查询api。