-
Notifications
You must be signed in to change notification settings - Fork 40
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
fix python3 incompatibility with json.loads #41
Conversation
if using python3, decode bytes to str befor using json.loads
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.
if sys.version_info[0] == 2: | ||
return json.loads(self.data) | ||
else: | ||
return json.loads(self.data.decode('utf8')) |
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.
I do hate the Python 2 and 3 differences in this way and more of, it confuses me. But I think in Python 2 it works because of it's default fallback to ascii
encoding which will probably break if there are actually special characters. Hence, I think we might always need to encode this. Let me do a test…
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.
Verified that it fails in Python 2 as well:
2016-11-20 23:25:02 ERROR [ca.py:395:safe_start_capture()] Start capture failed
2016-11-20 23:25:02 ERROR [ca.py:396:safe_start_capture()] Traceback (most recent call last):
File "pyca/ca.py", line 393, in safe_start_capture
return start_capture(event)
File "pyca/ca.py", line 264, in start_capture
f.write(value)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 506-510: ordinal not in range(128)
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.
Screw that, I should start actually reading error message -_-'. It fails even before that.
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.
To get all this fixed, I think we should set-up a unittest framework first. I've created a pullrequest for that. What do you think: #43
That should enable us to easily add Unicode tests :-)
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.
Sounds good. You can never have enough tests. :) Will look over your PR in a minute.
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.
Looks good. Let's take your version, obviously much better.
if using python3, decode bytes to str befor using json.loads
fixes #39