fuzeman/trakt-tools

Error writing to file during backup

outdooracorn opened this issue · 5 comments

Python version: 3.6.7
trakt-tools version: 0.1.8

Command executed: trakt_tools profile:backup:create --backup-dir TraktBackups

Output:

Would you like to continue? [yes]: 

Collection
 - Received 652 movie(s)
 - Writing to "collection/movies.json"...
ERROR:trakt_tools.tasks.profile.backup.create.handlers.collection:Unable to write collected items to disk: a bytes-like object is required, not 'str'
Traceback (most recent call last):
  File "/home/ollie/.local/lib/python3.6/site-packages/trakt_tools/tasks/profile/backup/create/handlers/collection.py", line 48, in run_media
    return backup.write(dest_path, items)
  File "/home/ollie/.local/lib/python3.6/site-packages/trakt_tools/models/backup.py", line 25, in write
    json.dump(data, fp, indent=4, sort_keys=True)
  File "/usr/lib/python3.6/json/__init__.py", line 180, in dump
    fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
Unable to backup profile, handler <trakt_tools.tasks.profile.backup.create.handlers.collection.CollectionHandler object at 0x7fad25af39e8> failed

Opening the file in text mode instead of binary mode ('w' instead of 'wb') at trakt_tools/models/backup.py:24 seems to fix the issue. This has only been used briefly with Python 3.6.7 though so don't know if this would break Python 2 support.

I appreciate you haven't committed to this in over 2 years and may no longer be interested.

I confirm the fix in #4 is sufficient. especially needed since with python2 errors out like:

@glensc this repo doesn't seem maintained anymore. I forked it and applied this fix.

I also added profile:backup:apply. Note that it doesn't do any deduplication when applying the backup so you'll probably have to do a history:duplicates:merge afterwards.

@outdooracorn did you ask owner @fuzeman to transfer ownership? would be nice to continue using same pip package.

Apologies for not having this issue fixed sooner. I'll have a new version released ASAP.

Thanks for your contributions @outdooracorn 👍

v0.2.1 is now available on PyPI