fuzeman / trakt-tools

Command-line tools for Trakt.tv.
37 stars 5 forks source link

Error writing to file during backup #1

Closed outdooracorn closed 4 years ago

outdooracorn commented 5 years ago

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.

glensc commented 4 years ago

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

outdooracorn commented 4 years ago

@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.

glensc commented 4 years ago

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

fuzeman commented 4 years ago

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

Thanks for your contributions @outdooracorn 👍

fuzeman commented 4 years ago

v0.2.1 is now available on PyPI