Skip to content
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

TypeError when browser returns 'bytes' instead of str' #22

Closed
ordnl opened this issue Jun 12, 2020 · 3 comments
Closed

TypeError when browser returns 'bytes' instead of str' #22

ordnl opened this issue Jun 12, 2020 · 3 comments

Comments

@ordnl
Copy link

ordnl commented Jun 12, 2020

OS: Debian GNU/Linux 9.9 x86_64
Python Version: 3.5.3
Chrome Version: Chromium 73

Neat tool you've got here. I've just tried this on Linux and it works fine with Chromium.

Only problem, was that I was getting TypeError: the JSON object must be str, not 'bytes', due to json.loads trying to parse, json_str which turns out to be bytes for me.

This can be fixed by changing line 198 in echo360/course.py to either:

            json_str = r.content.decode('utf-8')

or

            json_str = r.text
@soraxas
Copy link
Owner

soraxas commented Jun 12, 2020

Hi @ordnl thank you for your kind message

If you have Python2 installed in your system, would you be able to kindly verify that the proposed changes work in python2 as well? As I have tested it in both 2/3 with virtual environment myself but haven't encountered that before, therefore, might due to some special characters in your course data.

The problem that you are describing is a classical encoding issue that occurs in maintaining a python2/3 compatible project. I myself use py 3 but I tried to keep it works for both version as there are lots of users' system that has no python3 installed.

@ordnl
Copy link
Author

ordnl commented Jun 12, 2020

I have just tested both changes on Python 2.7.13, and it seems to work fine.

I had presumed this was due to some change made in Python 3. Also, I could not identify any special characters in the course data. I can only guess it may have been caused by the content-type header or something less visible, but I am unsure.

While Python 2 has reached end of life, I understand that there are still many who still use Python 2, so the desire to maintain support is very understandable.

@soraxas
Copy link
Owner

soraxas commented Jun 13, 2020

Thanks @ordnl for your verification, appreciate it. I would update the module based on your suggestion

soraxas added a commit that referenced this issue Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants