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

CannotSendHeader exception with 0.15

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.15.0
    • 0.17.0
    • Python - Library
    • None

    Description

      We recently started using thrift 0.15.0 after it was pushed to PyPI last week; previously, we were using 0.13.
      Since then, we've been receiving the following exception:

      # /tmp/thrift-error/bin/python test.py
      Traceback (most recent call last):
        File "test.py", line 16, in <module>
          transport.flush()
        File "/tmp/thrift-error/lib/python3.8/site-packages/thrift/transport/THttpClient.py", line 191, in flush
          self.__http.putheader('Cookie', self.headers['Set-Cookie'])
        File "/opt/python/lib/python3.8/http/client.py", line 1217, in putheader
          raise CannotSendHeader()
      http.client.CannotSendHeader
      

      Here's the test.py:

      test.py
      import thrift.transport.THttpClient
      
      URL = 'https://....'
      CA_FILE = '...'
      CERT_FILE = '...'
      KEY_FILE = '...'
      
      transport = thrift.transport.THttpClient.THttpClient(
          uri_or_host=URL,
          cafile=CA_FILE,
          cert_file=CERT_FILE,
          key_file=KEY_FILE
      )
      
      transport.flush()
      

      This appears to be a regression from THRIFT-5165 and https://github.com/apache/thrift/pull/2086.

      Based on the python source for http.client, HTTPConnection.putheader can only be called after a request has been started, and before it's been sent. (There's a state diagram at the top of that file).

      The current THttpClient.py calls HTTPConnection.putheader('Cookie', ...) after reading the response (and before it starts another request) - based on the code for both projects, it looks like if the server returns a Set-Cookie header, the client will always fail with the CannotSendHeader exception.

      Attachments

        Issue Links

          Activity

            People

              jensg Jens Geyer
              jeffreytolar Jeffrey Tolar
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h