dbr / tvnamer

Automatic TV episode file renamer, uses data from thetvdb.com via tvdb_api
https://pypi.python.org/pypi/tvnamer/
The Unlicense
907 stars 115 forks source link

UnicodeDecodeError #168

Closed georghuber closed 4 years ago

georghuber commented 4 years ago

Hi, I was using py27-tvnamer.

After installing py37-tvnamer (and having to install py37-sqlite3 after that) I receive the following output:

tvnamer ./ Loading config: /home/georg/.tvnamer.json '#################### '# Starting tvnamer '# Found 5 episodes

Traceback (most recent call last): File "/usr/local/bin/tvnamer", line 11, in load_entry_point('tvnamer==2.5', 'console_scripts', 'tvnamer')() File "/usr/local/lib/python3.7/site-packages/tvnamer/main.py", line 449, in main tvnamer(paths = sorted(args)) File "/usr/local/lib/python3.7/site-packages/tvnamer/main.py", line 351, in tvnamer cache=cache, File "/usr/local/lib/python3.7/site-packages/tvdb_api.py", line 726, in init self.session.remove_expired_responses() File "/usr/local/lib/python3.7/site-packages/requests_cache/core.py", line 159, in remove_expired_responses self.cache.remove_old_entries(datetime.utcnow() - self._cache_expire_after) File "/usr/local/lib/python3.7/site-packages/requests_cache/backends/base.py", line 110, in remove_old_entries response, created_at = self.responses[key] File "/usr/local/lib/python3.7/site-packages/requests_cache/backends/storage/dbdict.py", line 163, in getitem return pickle.loads(bytes(super(DbPickleDict, self).getitem(key))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 18074: ordinal not in range(128)

I reported this to the FreeBSD port maintainer who informed me that most likely I could find a better solution here on Github.

The filenames I use do not contain any Unicode characters. I even tried to rename the files to 'Greys.S15E15.mkv' in order to rule out any undiscovered Unicode characters.

dbr commented 4 years ago

I think it may just be the requests_cache cache file is not compatible between Python 2 and 3 (I thought I made the file name contain the python version to avoid this, but might be misremembering). If you remove this temp file it should work

georghuber commented 4 years ago

Thanks, I'll try that out. Do you know where I can find the requests_cache file?

georghuber commented 4 years ago

or do you mean to delete the entire directory in /usr/local/lib/python3.7/site-packages ?

georghuber commented 4 years ago

sorry for this flood, I deleted the entire directory, then removed the package py27-requests-cache.

Then I even un- and reinstalled py37-tvnamer and py37-tvdb_api

Still I get:

Loading config: /home/georg/.tvnamer.json

'####################
'# Starting tvnamer
'# Found 5 episodes

Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 11, in <module>
    load_entry_point('tvnamer==2.5', 'console_scripts', 'tvnamer')()
  File "/usr/local/lib/python3.7/site-packages/tvnamer/main.py", line 449, in main
    tvnamer(paths = sorted(args))
  File "/usr/local/lib/python3.7/site-packages/tvnamer/main.py", line 351, in tvnamer
    cache=cache,
  File "/usr/local/lib/python3.7/site-packages/tvdb_api.py", line 726, in __init__
    self.session.remove_expired_responses()
  File "/usr/local/lib/python3.7/site-packages/requests_cache/core.py", line 159, in remove_expired_responses
    self.cache.remove_old_entries(datetime.utcnow() - self._cache_expire_after)
  File "/usr/local/lib/python3.7/site-packages/requests_cache/backends/base.py", line 110, in remove_old_entries
    response, created_at = self.responses[key]
  File "/usr/local/lib/python3.7/site-packages/requests_cache/backends/storage/dbdict.py", line 163, in __getitem__
    return pickle.loads(bytes(super(DbPickleDict, self).__getitem__(key)))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 18074: ordinal not in range(128)
dbr commented 4 years ago

Sorry for the slow reply!

The requests cache file will live in your system temp folder, which you can find by running in a terminal:

python -c 'import tempfile; print(tempfile.gettempdir())'

In that directory there will be a folder beginning with "tvdb"

georghuber commented 4 years ago

Hi, sorry for my even slower reply :-) and thanks for your effort.

Unfortunately, I did not find the "requests_cache" file in my system temp filesysten (/tmp).

However 'find -name "requests_cache" found the following two instances:

/usr/local/lib/python3.7/site-packages/requests_cache /usr/local/lib/python2.7/site-packages/requests_cache

Should I just delete the second requests_cache file in /usr/lib/python2.7/.. ?

Many thanks again for your help

Georg

Am Di., 4. Feb. 2020 um 04:52 Uhr schrieb dbr notifications@github.com:

Sorry for the slow reply!

The requests cache file will live in your system temp folder, which you can find by running in a terminal:

python -c 'import tempfile; print(tempfile.gettempdir())'

In that directory there will be a folder beginning with "tvdb"

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dbr/tvnamer/issues/168?email_source=notifications&email_token=ABQFXMVGER4IEL4H7DWPXADRBDQ77A5CNFSM4KHTCTLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKWIFNY#issuecomment-581730999, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQFXMU5C7TBX24EIU6ER33RBDQ77ANCNFSM4KHTCTLA .

dbr commented 4 years ago

Hmm, removing the python2.7 dir shouldn't have much effect (it'd only remove the Python library itself, which would only prevent tvnamer functioning under Python 2.7 - if that doesn't matter, removing it would be harmless)

The cache file starts with tvdb_api rather than requests_cache - specifically the cache file can be found by running this:

$ python -c 'import tvdb_api; print(tvdb_api.Tvdb()._getTempDir() + ".sqlite")'

For example, for me on macOS it is named: /var/folders/fk/bccr247962g1c2vmp6mn_g500000an/T/tvdb_api-u501.sqlite

georghuber commented 4 years ago

Hi thanks for your response.

I have tried the python command you suggested, and I receive this:

root@FreeBSD:/home/georg # python3.7 -c 'import tvdb_api; print(tvdb_api.Tvdb()._getTempDir() + ".sqlite")' Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/site-packages/tvdb_api.py", line 726, in init self.session.remove_expired_responses() File "/usr/local/lib/python3.7/site-packages/requests_cache/core.py", line 159, in remove_expired_responses self.cache.remove_old_entries(datetime.utcnow() - self._cache_expire_after) File "/usr/local/lib/python3.7/site-packages/requests_cache/backends/base.py", line 110, in remove_old_entries response, created_at = self.responses[key] File "/usr/local/lib/python3.7/site-packages/requests_cache/backends/storage/dbdict.py", line 163, in getitem return pickle.loads(bytes(super(DbPickleDict, self).getitem(key))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1313: ordinal not in range(128) root@FreeBSD:/home/georg #

Which is basically the same error message as with tvnamer. Is this due to importing the tvdb_api, or is it "a python thing"?

I have searched for the file "the old way" and found the following files (also in my /tmp filesystem):

-rw-r--r-- 1 root wheel 135168 Apr 8 2018 tvdb_api-u0.sqlite drwxr-xr-x 2 georg wheel 20 Sep 10 2017 tvdb_api-u1001/ -rw-r--r-- 1 georg wheel 1617920 Mar 25 22:04 tvdb_api-u1001.sqlite

should I delete (any or all of) these files?

Many thanks, I appreciate it.

Georg

Am Fr., 27. März 2020 um 06:13 Uhr schrieb dbr notifications@github.com:

Hmm, removing the python2.7 dir shouldn't have much effect (it'd only remove the Python library itself, which would only prevent tvnamer functioning under Python 2.7 - if that doesn't matter, removing it would be harmless)

The cache file starts with tvdb_api rather than requests_cache - specifically the cache file can be found by running this:

$ python -c 'import tvdb_api; print(tvdb_api.Tvdb()._getTempDir() + ".sqlite")'

For example, for me on macOS it is named: /var/folders/fk/bccr247962g1c2vmp6mn_g500000an/T/tvdb_api-u501.sqlite

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dbr/tvnamer/issues/168#issuecomment-604818936, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQFXMS6GJKSJECU4KWGGZTRJQYX3ANCNFSM4KHTCTLA .

dbr commented 4 years ago

Oops, that is indeed exactly the same error! However doesn't matter, as those look like the problematic files! Removing those should fix things I hope

georghuber commented 4 years ago

Many thanks, that did solve the problem!

Thanks again for your effort!

Georg

Am Fr., 27. März 2020 um 11:44 Uhr schrieb dbr notifications@github.com:

Oops, that is indeed exactly the same error! However doesn't matter, as those look like the problematic files! Removing those should fix things I hope

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dbr/tvnamer/issues/168#issuecomment-604932640, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQFXMVXUDMEYNUG4ZTCKW3RJR7PJANCNFSM4KHTCTLA .

dbr commented 4 years ago

Excellent, glad you got it working!

I've made another ticket to make this problem easier to debug in future - #174