thrift icon indicating copy to clipboard operation
thrift copied to clipboard

Fix bug in Python's THttpClient proxy handling

Open pspeter opened this issue 3 years ago • 3 comments
trafficstars

Previously, creating an instance of this class would throw whenever the http(s)_proxy environment variables were set, since it tried concatenating a string with a bytes array.

pspeter avatar Apr 13 '22 12:04 pspeter

@fishy the return type of the function should now always be str in Python 2 and 3, so it is consistent to the current behavior in Python2 while also fixing the function in Python 3.

pspeter avatar Apr 20 '22 08:04 pspeter

This is the correct type, yes, but it's not the correct string:

$ python3
Python 3.10.4 (main, Mar 24 2022, 13:07:27) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import base64
>>> str(base64.b64encode(b'foo'))
"b'Zm9v'"

fishy avatar Apr 20 '22 15:04 fishy

You're right, ensure_str it is.

Python 3:

>>> cr = b"abc"
>>> "Basic " + six.ensure_str(cr)
'Basic abc'

Python 2:

>>> cr = "abc"
>>> "Basic " + six.ensure_str(cr)
'Basic abc'

Thanks for your sharp eye! :)

pspeter avatar Apr 21 '22 08:04 pspeter