-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not return bytes, but str #485
Do not return bytes, but str #485
Conversation
What does this error mean please?
|
nailgun/entities.py
Outdated
@@ -4383,7 +4383,8 @@ def download_debug_certificate(self, synchronous=True, **kwargs): | |||
kwargs.update(self._server_config.get_client_kwargs()) | |||
response = client.get( | |||
self.path('download_debug_certificate'), **kwargs) | |||
return _handle_response(response, self._server_config, synchronous) | |||
return str(_handle_response( | |||
response, self._server_config, synchronous)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work in py3 this will return something like b'***'.
Please use decode('utf-8') that will work in py2 and py3.
@jhutar seems not that simple as it appear, and it seems by changing that return will affect unittests, we have to decide is nailgun default content return should be bytes or string under py3 (in case of string we have to change the unitests) if we cannot come to a consensus on this, we have to change the tests to verify the type of the returned values from nailgun response content. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NACK
str representation of bytes is
b'string'
(including qoutes and b)
This has to be resolved by using .decode('utf-8')
FYI I had hard times figuring this out for SatelliteQE/automation-tools#671
Python 3.6.4
Oops, while decode is OK:
So please use |
we have two alternatives For me I prefer (and recommend) the first one as nailgun is higher lib over basic network api lib and it's logical to receive and return user ready data. Of course this need more effort as nailgun unit-tests needs to be fixed. but this will allow us to not fix all the tests that we know (and the ones not yet found) to be broken on py3. |
But an other issue if we go with the first variant, if some function are already decoding that content they have to be fixed to not do so (as exception will be raised on py3 AttributeError , on py2 UnicodeEncodeError). |
Are we positive that Nailgun needs to support both Python 3 and 2? Is that a strong decision? |
Wont be in the mtg. There are vacations at Fry and Mon in the CZ. |
So, I do not insist on what I have committed. If you want it in a different way, please let me know how. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you change _handler_reponse()
?
https://github.com/SatelliteQE/nailgun/blob/master/nailgun/entities.py#L125-L126
with something like:
if isinstance(response.content, bytes):
return response.content.decode('utf-8')
else:
return response.content
WYT?
Done, please re-review. |
Oh my, it so easy to close... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant solution :-)
to other reviewers: Please "Squash and merge" this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, think we need a third reviewer for this as this is making default content return as string on py3 @rochacbruno @renzon @abalakh please review
@lpramuk @rochacbruno @renzon @abalakh anyway we have string return in py2 perhaps this is not a concern but that was the default request content return. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
LGTM
* Do not return bytes, but str * Fix issue reviewers found. Thanks! * Alter tests to pass for download_debug_certificate * Fix too long line * This makes it easier - thank you lpramuk
Fixes #484