dbr / tvnamer

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

After python3.8 update I receive error #210

Open georghuber opened 2 years ago

georghuber commented 2 years ago

Hi, I recently installed the latest python3.8 update (3.8.13) via pkg (FreeBSD).

Now I receive the following error with tvnamer:

tvnamer .

Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 33, in <module>
    sys.exit(load_entry_point('tvnamer==3.0.4', 'console_scripts', 'tvnamer')())
  File "/usr/local/bin/tvnamer", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/local/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.8/site-packages/tvnamer/main.py", line 18, in <module>
    import tvdb_api
  File "/usr/local/lib/python3.8/site-packages/tvdb_api.py", line 34, in <module>
    from requests_cache.backends.base import _to_bytes, _DEFAULT_HEADERS
ImportError: cannot import name '_to_bytes' from 'requests_cache.backends.base' (/usr/local/lib/python3.8/site-packages/requests_cache/backends/base.py)

Unfortunately I am a Python illiterate. Is this a problem with tvnamer?

Many thanks

Georg

JWCook commented 2 years ago

It looks like tvdb_api was importing some internal functions from requests-cache. So not a problem with tvnamer.

That appears to have been fixed here, so try updating to the latest version:

pip install -U tvdb_api
georghuber commented 2 years ago

Many thanks; I'll contact the maintainer from FreeBSD ports, because their latest tvdb_api version was from a year ago.

georghuber commented 2 years ago

Hi,

I still could not get it to work. I am at py39 now but I receive this message (FreeBSD 13.1):

####################
# Starting tvnamer
Invalid filename: Cannot parse '/mnt/large/rename/tvnamer.json'
# Found 1 episode
####################
# Processing file: star.trek.strange.new.world.s01e10.mkv
# Detected series: star trek strange new world (season: 1, episode: 10)
Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 33, in <module>
    sys.exit(load_entry_point('tvnamer==3.0.4', 'console_scripts', 'tvnamer')())
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 474, in main
    tvnamer(paths = sorted(args))
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 370, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 175, in processFile
    episode.populateFromTvdb(tvdb_instance, force_name=Config['force_name'], series_id=Config['series_id'])
  File "/usr/local/lib/python3.9/site-packages/tvnamer/utils.py", line 641, in populateFromTvdb
    show = tvdb_instance[force_name or self.seriesname]
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 1152, in __getitem__
    sid = self._nameToSid(key)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 1136, in _nameToSid
    selected_series = self._getSeries(name)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 935, in _getSeries
    all_series = self.search(series)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 914, in search
    series_resp = self._getetsrc(self.config['url_getSeries'] % (series))
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 874, in _getetsrc
    src = self._loadUrl(url, language=language)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 811, in _loadUrl
    self.authorize()
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 859, in authorize
    r = self.session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 115, in request
    return super().request(method, url, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 127, in send
    cache_key = self.cache.create_key(request, **kwargs)
TypeError: create_key() got an unexpected keyword argument 'timeout'

Is this a tvnamer error, or a tvdb_api error?

Many thanks for your help!

Georg

JWCook commented 2 years ago

That might be a problem with requests-cache, or at least an older version of it. Can you tell me what version you have?

python -c "import requests_cache; print(requests_cache.__version__)"

And are you able to update to a newer version?

georghuber commented 2 years ago

Hi,

thanks for your help. I forgot to mention, that meanwhile I have upgraded python to 3.9 and both tvdb_api and tvnamer are py39-.

Requests cache is (according to your command): 0.9.2

Thanks again,

Georg

georghuber commented 2 years ago

as for the possibility to update to a newer version:

the port I have installed is supposedly "required" by tvdb_api to run (see freshports: https://www.freshports.org/www/py-requests-cache93/). I believe the port maintainer specifically forked this version, after I had troubles with requests_cache (see inital post above).

However, there seems to be a "newer" port available (version number 0.9.5; https://www.freshports.org/www/py-requests-cache/). As I am a total python noob however, I do not know, whether the "new" 0.9.5 port would change/or fix anything. Since the port maintainer created the 0.9.3 fork specifically for tvdb_api, I do not know, whether installing the 0.9.5 port would change anything (as tvdb_api would possibly continue to use the request_cache 0.9.3).

Many thanks for the help, again!

G

georghuber commented 2 years ago

Hi,

the latest info in the FreeBSD ports community I received is:

Looks like they do not support python 3.9 so you should go back to python38.

Add in your make.conf: DEFAULT_VERSIONS= python=3.8 and rebuild all ports.

Do you think that this is worth a shot?

Many thanks!

Georg

JWCook commented 2 years ago

tvnamer's classifiers (used for metadata on PyPI) only list python versions up to 3.8, but that doesn't necessarily mean it doesn't work with python 3.9+. Often that just means it hasn't been tested on later versions.

I looked into this error a bit more:

  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 127, in send
    cache_key = self.cache.create_key(request, **kwargs)
TypeError: create_key() got an unexpected keyword argument 'timeout'

I had assumed this was a problem with requests-cache's create_key() function, but couldn't reproduce it. Then I found that tvdb_api is patching that out with a custom key function here: https://github.com/dbr/tvdb_api/blob/ce0382181a9e08a5113bfee0fed2c78f8b1e613f/tvdb_api.py#L702

One way or another, a timeout keyword arg got passed to that function, probably to set the connection timeout in the requests library. requests-cache's create_key() handles variable keyword args (**kwargs), which would include timeout. The purpose of that is to provide the option to use any extra keyword arguments passed to requests.request(). However, the custom create_key() used by tvdb_api only takes a single positional argument, resulting in TypeError: create_key() got an unexpected keyword argument 'timeout'. That's probably more info than you need, but just leaving it here for reference.

Edit: I added a minimal PR that will fix this: https://github.com/dbr/tvdb_api/pull/102

JWCook commented 2 years ago

Meanwhile, I can't actually figure out where that timeout argument is coming from. I don't see it used anywhere in either tvnamer or tvdb_api, so it's possible that updating to the latest version of one or both of them may fix the issue.

georghuber commented 2 years ago

Meanwhile, I can't actually figure out where that timeout argument is coming from. I don't see it used anywhere in either tvnamer or tvdb_api, so it's possible that updating to the latest version of one or both of them may fix the issue.

Many thanks for looking into it.

I have the latest versions of both installed, otherwise I would not dare to ask in a forum ;-)

BSD% tvnamer --version
tvnamer version: 3.0.4
tvdb_api version: 3.1.0
georghuber commented 2 years ago

tvnamer's classifiers (used for metadata on PyPI) only list python versions up to 3.8, but that doesn't necessarily mean it doesn't work with python 3.9+. Often that just means it hasn't been tested on later versions.

I looked into this error a bit more:

  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 127, in send
    cache_key = self.cache.create_key(request, **kwargs)
TypeError: create_key() got an unexpected keyword argument 'timeout'

I had assumed this was a problem with requests-cache's create_key() function, but couldn't reproduce it. Then I found that tvdb_api is patching that out with a custom key function here: https://github.com/dbr/tvdb_api/blob/ce0382181a9e08a5113bfee0fed2c78f8b1e613f/tvdb_api.py#L702

One way or another, a timeout keyword arg got passed to that function, probably to set the connection timeout in the requests library. requests-cache's create_key() handles variable keyword args (**kwargs), which would include timeout. The purpose of that is to provide the option to use any extra keyword arguments passed to requests.request(). However, the custom create_key() used by tvdb_api only takes a single positional argument, resulting in TypeError: create_key() got an unexpected keyword argument 'timeout'. That's probably more info than you need, but just leaving it here for reference.

Edit: I added a minimal PR that will fix this: dbr/tvdb_api#102

Many thanks. I ran tvnamer with the -v option, maybe it is of additional help:

BSD% tvnamer -v /mnt/large/rename/star.trek.strange.new.world.s01e10.mkv
####################
# Starting tvnamer
# Found 1 episode
2022-10-02 19:39:05,416 - tvnamer.main - DEBUG - Using tvnamer default API key
2022-10-02 19:39:05,418 - tvdb_api - DEBUG - Caching using requests_cache to /tmp/tvdb_api--u1001-py3
2022-10-02 19:39:05,418 - requests_cache.backends - DEBUG - Initializing backend: sqlite /tmp/tvdb_api--u1001-py3
2022-10-02 19:39:05,418 - requests_cache.backends.base - DEBUG - Initializing SQLitePickleDict with serializer: <requests_cache.serializers.pipeline.SerializerPipeline object at 0x802a1ebe0>
2022-10-02 19:39:05,418 - requests_cache.backends.sqlite - DEBUG - Opening connection to /tmp/tvdb_api--u1001-py3.sqlite:responses
2022-10-02 19:39:05,419 - requests_cache.backends.base - DEBUG - Initializing SQLiteDict with serializer: <requests_cache.serializers.pipeline.SerializerPipeline object at 0x802a1ebe0>
2022-10-02 19:39:05,419 - requests_cache.backends.sqlite - DEBUG - Opening connection to /tmp/tvdb_api--u1001-py3.sqlite:redirects
2022-10-02 19:39:05,419 - requests_cache.backends.base - INFO - Removing expired responses.
2022-10-02 19:39:05,419 - requests_cache.backends.base - DEBUG - Deleting 0 invalid/expired responses
2022-10-02 19:39:05,425 - requests_cache.backends.base - DEBUG - Deleting 0 expired responses
####################
# Processing file: star.trek.strange.new.world.s01e10.mkv
# Detected series: star trek strange new world (season: 1, episode: 10)
2022-10-02 19:39:05,431 - tvdb_api - DEBUG - Getting show star trek strange new world
2022-10-02 19:39:05,431 - tvdb_api - DEBUG - Searching for show star%20trek%20strange%20new%20world
2022-10-02 19:39:05,432 - tvdb_api - DEBUG - auth
Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 33, in <module>
    sys.exit(load_entry_point('tvnamer==3.0.4', 'console_scripts', 'tvnamer')())
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 474, in main
    tvnamer(paths = sorted(args))
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 370, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 175, in processFile
    episode.populateFromTvdb(tvdb_instance, force_name=Config['force_name'], series_id=Config['series_id'])
  File "/usr/local/lib/python3.9/site-packages/tvnamer/utils.py", line 641, in populateFromTvdb
    show = tvdb_instance[force_name or self.seriesname]
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 1152, in __getitem__
    sid = self._nameToSid(key)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 1136, in _nameToSid
    selected_series = self._getSeries(name)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 935, in _getSeries
    all_series = self.search(series)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 914, in search
    series_resp = self._getetsrc(self.config['url_getSeries'] % (series))
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 874, in _getetsrc
    src = self._loadUrl(url, language=language)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 811, in _loadUrl
    self.authorize()
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 859, in authorize
    r = self.session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 115, in request
    return super().request(method, url, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 127, in send
    cache_key = self.cache.create_key(request, **kwargs)
TypeError: create_key() got an unexpected keyword argument 'timeout'

Thank you, I really appreciate the effort (and the tool btw ;-)

Georg

georghuber commented 2 years ago

I think we are getting ahead, but not quite there yet. The maintainer of the tvdb_api port included your fix but now I am getting this error:

tvnamer star.trek.strange.new.world.s01e10.mkv
####################
# Starting tvnamer
# Found 1 episode
####################
# Processing file: star.trek.strange.new.world.s01e10.mkv
# Detected series: star trek strange new world (season: 1, episode: 10)
Traceback (most recent call last):
  File "/usr/local/bin/tvnamer", line 33, in <module>
    sys.exit(load_entry_point('tvnamer==3.0.4', 'console_scripts', 'tvnamer')())
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 474, in main
    tvnamer(paths = sorted(args))
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 370, in tvnamer
    processFile(tvdb_instance, episode)
  File "/usr/local/lib/python3.9/site-packages/tvnamer/main.py", line 175, in processFile
    episode.populateFromTvdb(tvdb_instance, force_name=Config['force_name'], series_id=Config['series_id'])
  File "/usr/local/lib/python3.9/site-packages/tvnamer/utils.py", line 641, in populateFromTvdb
    show = tvdb_instance[force_name or self.seriesname]
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 1152, in __getitem__
    sid = self._nameToSid(key)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 1136, in _nameToSid
    selected_series = self._getSeries(name)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 935, in _getSeries
    all_series = self.search(series)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 914, in search
    series_resp = self._getetsrc(self.config['url_getSeries'] % (series))
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 874, in _getetsrc
    src = self._loadUrl(url, language=language)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 811, in _loadUrl
    self.authorize()
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 859, in authorize
    r = self.session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 115, in request
    return super().request(method, url, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests_cache/session.py", line 127, in send
    cache_key = self.cache.create_key(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/tvdb_api.py", line 547, in create_key
    if self._ignored_parameters:
AttributeError: 'SQLiteCache' object has no attribute '_ignored_parameters'

I am so sorry causing so much trouble, but I just can't give up now that we are about there :-)

Georg

berarma commented 1 year ago

I've created PR dbr/tvdb_api#105 that fixes the issues with new requests-cache.

docbrown0621 commented 1 year ago

I've created PR dbr/tvdb_api#105 that fixes the issues with new requests-cache.

Just installed on Debian 12 (bookworm) and applied the above fixes. Works perfectly with python 3.11, THANK YOU!!!

nosrednawall commented 11 months ago

In Debian 12 i installed the pipx with apt and tvnamer with pipx, according to bellow code

sudo apt install pipx
pipx install tvnamer --include-deps
pipx ensurepath

Thanks!