soraxas / echo360

Commandline tool for automated downloads of echo360 videos hosted by university
https://cs.tinyiu.com/echo360
MIT License
276 stars 52 forks source link

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

Closed ordnl closed 4 years ago

ordnl commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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