Python SSL通信在读取时挂起,然后出现错误54 - 连接被对方重置

4 投票
1 回答
1520 浏览
提问于 2025-04-16 01:38

我正在用Python和一些库(suds和python-ntlm)调用微软CRM的网络服务,但在读取SSL数据时,调用一直卡住。这个CRM服务提供商有测试服务和正式服务,我可以顺利连接测试服务(虽然上面没有什么有用的数据),但主要的服务却一直卡住。

这是我在中断这个过程后看到的错误信息:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

INFO:root:Getting WSDL from file:///Users/crose/projects/aed/2366/crm/services/metadata.wsdl
DEBUG:suds.client:sending to (https://service.host/MSCrmServices/2007/MetadataService.asmx)
message:
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/crm/2007/WebServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns0:Body>
      <ns1:Execute>
         <ns1:Request xsi:type="ns1:RetrieveAttributeRequest">
            <ns1:MetadataId>00000000-0000-0000-0000-000000000000</ns1:MetadataId>
            <ns1:EntityLogicalName>opportunity</ns1:EntityLogicalName>
            <ns1:LogicalName>new_typeofcontact</ns1:LogicalName>
            <ns1:RetrieveAsIfPublished>false</ns1:RetrieveAsIfPublished>
         </ns1:Request>
      </ns1:Execute>
   </ns0:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': u'"http://schemas.microsoft.com/crm/2007/WebServices/Execute"', 'Content-Type': 'text/xml'}
DEBUG:suds.transport.http:sending:
URL:https://service.host/MSCrmServices/2007/MetadataService.asmx
HEADERS: {'SOAPAction': u'"http://schemas.microsoft.com/crm/2007/WebServices/Execute"', 'Content-Type': 'text/xml', 'Content-type': 'text/xml', 'Soapaction': u'"http://schemas.microsoft.com/crm/2007/WebServices/Execute"'}
MESSAGE:
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/crm/2007/WebServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns0:Body>
      <ns1:Execute>
         <ns1:Request xsi:type="ns1:RetrieveAttributeRequest">
            <ns1:MetadataId>00000000-0000-0000-0000-000000000000</ns1:MetadataId>
            <ns1:EntityLogicalName>opportunity</ns1:EntityLogicalName>
            <ns1:LogicalName>new_typeofcontact</ns1:LogicalName>
            <ns1:RetrieveAsIfPublished>false</ns1:RetrieveAsIfPublished>
         </ns1:Request>
      </ns1:Execute>
   </ns0:Body>
</SOAP-ENV:Envelope>
  C-c C-cTraceback (most recent call last):
  File "sudstest2.py", line 40, in <module>
    attr = metadata_client.service.Execute(mdRequest(*picklist))
  File "/Users/crose/virtualenv/advanis/lib/python2.6/site-packages/suds/client.py", line 539, in __call__
    return client.invoke(args, kwargs)
  File "/Users/crose/virtualenv/advanis/lib/python2.6/site-packages/suds/client.py", line 598, in invoke
    result = self.send(msg)
  File "/Users/crose/virtualenv/advanis/lib/python2.6/site-packages/suds/client.py", line 623, in send
    reply = transport.send(request)
  File "/Users/crose/virtualenv/advanis/lib/python2.6/site-packages/suds/transport/https.py", line 64, in send
    return  HttpTransport.send(self, request)
  File "/Users/crose/virtualenv/advanis/lib/python2.6/site-packages/suds/transport/http.py", line 77, in send
    fp = self.u2open(u2request)
  File "/Users/crose/virtualenv/advanis/lib/python2.6/site-packages/suds/transport/http.py", line 118, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/urllib2.py", line 397, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/urllib2.py", line 510, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/urllib2.py", line 429, in error
    result = self._call_chain(*args)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/Users/crose/virtualenv/advanis/src/python-ntlm/ntlm/HTTPNtlmAuthHandler.py", line 96, in http_error_401
    return self.http_error_authentication_required('www-authenticate', req, fp, headers)
  File "/Users/crose/virtualenv/advanis/src/python-ntlm/ntlm/HTTPNtlmAuthHandler.py", line 35, in http_error_authentication_required
    return self.retry_using_http_NTLM_auth(req, auth_header_field, None, headers)
  File "/Users/crose/virtualenv/advanis/src/python-ntlm/ntlm/HTTPNtlmAuthHandler.py", line 80, in retry_using_http_NTLM_auth
    response = h.getresponse()
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/httplib.py", line 986, in getresponse
    response.begin()
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/httplib.py", line 349, in _read_status
    line = self.fp.readline()
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/socket.py", line 397, in readline
    data = recv(1)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/ssl.py", line 96, in <lambda>
    self.recv = lambda buflen=1024, flags=0: SSLSocket.recv(self, buflen, flags)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/ssl.py", line 217, in recv
    return self.read(buflen)
  File "/usr/local/Cellar/python/2.6.5/lib/python2.6/ssl.py", line 136, in read

KeyboardInterrupt

最终,我等了很久后,收到了一个连接错误54 - 连接被对方重置。

我该如何调试这个问题呢?

1 个回答

0

我猜可能是HTTP头里面的某些东西搞混了。你可以试着用wget或者curl这两个工具来发同样的请求,记得打开调试或详细模式,看看它们返回了什么。

另外,也有可能是你登录这个服务的次数太多,速度太快了。我之前遇到过这种情况,不过也可能不是这个原因,反正可以检查一下。

撰写回答