Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-155

Python THttpClient should handle opening HTTP layer on each request automatically

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • Python - Library
    • None
    • Patch Available

    Description

      The HTTP transport for other languages (like Java) will automatically open the HTTP connection on each Thrift message in the flush() method.

      The Python THttpClient requires you to explicitly call .open() on the low-level transport before every Thrift invocation. If you don't do this, you'll get a "ResponseNotReady" error out of httplib:

      ...
      self._oprot.trans.flush()
      File "/Users/dave/dev/work/en-thrift/target/evernote-api-1.10/lib/python/thrift/transport/THttpClient.py", line 60, in flush
      self.code, self.message, self.headers = self.__http.getreply()
      File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", line 1195, in getreply
      response = self._conn.getresponse()
      File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", line 914, in getresponse
      raise ResponseNotReady()
      httplib.ResponseNotReady

      I'm submitting a small patch to THttpClient.py that will automatically handle the opening of the required low-level HTTP connection with each Thrift message in the beginning of the flush() method:

      Index: lib/py/src/transport/THttpClient.py
      ===================================================================
      — lib/py/src/transport/THttpClient.py (revision 701711)
      +++ lib/py/src/transport/THttpClient.py (working copy)
      @@ -37,6 +37,10 @@
      self.__wbuf.write(buf)

      def flush(self):
      + if self.isOpen():
      + self.close()
      + self.open();
      +

      1. Pull data out of buffer
        data = self.__wbuf.getvalue()
        self.__wbuf = StringIO()

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            engberg Dave Engberg
            engberg Dave Engberg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment