Jeffrey Tolar created THRIFT-5467:
-------------------------------------
Summary: python: CannotSendHeader exception with 0.15
Key: THRIFT-5467
URL: https://issues.apache.org/jira/browse/THRIFT-5467
Project: Thrift
Issue Type: Bug
Components: Python - Library
Affects Versions: 0.15.0
Reporter: Jeffrey Tolar
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:
{noformat}
# /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
{noformat}
Here's the {{test.py}}:
{noformat:title=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()
{noformat}
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}}|https://github.com/python/cpython/blob/a450398933d265011e1e8eae7f771b70f97945fb/Lib/http/client.py#L1237-L1238],
{{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}}|https://github.com/apache/thrift/blob/cb808fcb79d03028c6138891381689e1ef4e4a94/lib/py/src/transport/THttpClient.py#L191]
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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)