xmlrpclib hangs execution

itkovian itkovian at gmail.com
Thu Jun 14 09:44:55 EDT 2007


On Jun 14, 3:10 pm, itkov... at gmail.com wrote:
> Hi,
>
> > 2. The Python implementation ofxmlrpcis not very robust. It just waits for
> > the connection to close. A well-written client (like your Java client)
> > would detect the presence of a Content-Length header and use that.
>
> I'm facing a similar ordeal here. I think the right thing to do would
> be to adjust the xmlrpc library to parse the header and check for the
> Content-Length. Right now, the socket seems to read 1024 bytes, so
> naturally, when the connection closes, the socket throws an error,
> because it thinks that more bytes are coming. Which sounds rather
> weird to me, given the fact that in rare cases the reply will be a
> multiple of 1024 bytes :-)
>
> -- Andy Georges

For now, these changes helped me out. It probably (read: certainly)
needs some cleanup, and I'm probably not taking everything into
account as I should:

--- xmlrpclib.py        2007-06-14 15:42:36.000000000 +0200
+++ /sw/lib/python2.5/xmlrpclib.py      2006-11-29 02:46:38.000000000
+0100
@@ -1184,11 +1184,6 @@

         errcode, errmsg, headers = h.getreply()

-        expected_payload_length = 1024
-        if headers.has_key('content-length'):
-          expected_payload_length = int(headers['content-length'])
-
-
         if errcode != 200:
             raise ProtocolError(
                 host + handler,
@@ -1203,7 +1198,7 @@
         except AttributeError:
             sock = None

-        return self._parse_response(h.getfile(), sock,
expected_payload_length)
+        return self._parse_response(h.getfile(), sock)

     ##
     # Create parser.
@@ -1323,23 +1318,21 @@
     #    could not be accessed).
     # @return Response tuple and target method.

-    def _parse_response(self, file, sock, size=1024):
+    def _parse_response(self, file, sock):
         # read response from input file/socket, and parse it

         p, u = self.getparser()

         while 1:
             if sock:
-                response = sock.recv(size)
+                response = sock.recv(1024)
             else:
-                response = file.read(size)
+                response = file.read(1024)
             if not response:
                 break
             if self.verbose:
                 print "body:", repr(response)
             p.feed(response)
-            if len(response) == size:
-                break

         file.close()
         p.close()


-- Andy Georges




More information about the Python-list mailing list