Fix ParamikoSSHClient.run() so that it works in Python 3.4.1#347
Closed
ereyes01 wants to merge 1 commit into
Closed
Fix ParamikoSSHClient.run() so that it works in Python 3.4.1#347ereyes01 wants to merge 1 commit into
ereyes01 wants to merge 1 commit into
Conversation
incoming bytes into strings using the bytes decode method.
Member
|
Good catch, the same issue should exist in all the Python 3.x versions where bytes / unicode handling has been changed. |
Member
There was a problem hiding this comment.
Looks good.
Only thing I would do is wrap data with libcloud.utils.py3 with b function call to be on the safe side and make sure that type of data is in fact bytes in Python 3 (if for some reason, data is not bytes in Python 3, decode call will throw).
I'll go ahead and make this change.
Member
|
Merged into trunk. Thanks. |
Contributor
Author
|
Thank you for merging, and for the quick response! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was trying to do the following using apache-libcloud==0.15.1 on Python 3.4.1:
The deploy_node would work fine in Python 2.7.6 but failed when I switched to Python 3,4,1 with the following:
After instrumenting the code to print more informative stack traces, I located the source of the Exception, which was in ParamikoSSHClient.run(). The code where a data chunk is obtained from chan.recv() returns a bytes object in Python 3, where it presumably returns a descendant of basestring in Python 2. This object is then passed to stdout.write() (or stderr.write), which blows up because it's not a stringy value.
My change decodes the bytes into strings as they are passed into those write() methods.
This change made deploy_node() work in my code for Python 3.4.1. I'm not sure if the same type of bug exists elsewhere, but this fix is what I needed to unblock myself.
Thanks for the excellent library, and I hope this helps.