TM1 REST API Python请求ConnectionResetError MaxRetryError Prox



我正在尝试使用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个错误。

作为参考,相同的url是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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestspackagesurllib3connectionpool.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestspackagesurllib3connectionpool.py in _prepare_proxy(self, conn)
    779 
--> 780         conn.connect()
    781 
C:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestspackagesurllib3connection.py in connect(self)
    288                                     server_hostname=hostname,
--> 289                                     ssl_version=resolved_ssl_version)
    290 
C:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestspackagesurllib3utilssl_.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:UsersvmoraAppDataLocalContinuumAnaconda3libssl.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:UsersvmoraAppDataLocalContinuumAnaconda3libssl.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:UsersvmoraAppDataLocalContinuumAnaconda3libssl.py in do_handshake(self, block)
    987                 self.settimeout(None)
--> 988             self._sslobj.do_handshake()
    989         finally:
C:UsersvmoraAppDataLocalContinuumAnaconda3libssl.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestsadapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    402                     retries=self.max_retries,
--> 403                     timeout=timeout
    404                 )
C:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestspackagesurllib3connectionpool.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestspackagesurllib3utilretry.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestssessions.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestssessions.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestssessions.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:UsersvmoraAppDataLocalContinuumAnaconda3libsite-packagesrequestsadapters.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)))

几个同事帮我解决了这个问题。我在环境变量中设置的http和https代理导致了这个问题。我删除了它们/重新启动/然后能够查询api

相关内容

  • 没有找到相关文章

最新更新