dbr/tvdb_api

ImportError: cannot import name '_to_bytes'

Closed this issue · 4 comments

With the release of requests-cache 0.6.0 the _to_bytes method is no longer available and tvdb_api depends on this method

This results in this error

  File "/path/to/.virtualenvs/tvnamer/lib/python3.6/site-packages/tvdb_api.py", line 35, in <module>
    from requests_cache.backends.base import _to_bytes, _DEFAULT_HEADERS
ImportError: cannot import name '_to_bytes'

One mitigation would be to limit the versions of requests-cache to 0.5.0 or earlier

Temporary fix: pip install requests-cache==0.5.0

dbr commented

New release of tvdb_api should fix this for now, tvdb_api==3.1.0

Hi, I'm unsure why this still doesn't work here, so any hint appreciated.
I'm on a Manjaro system (22.0.0, Codename Sikaris) and installed via pacman:

To install (1):
  python-cattrs          22.2.0-2  (Required By: python-requests-cache)  community
To build (4):
  python-url-normalize   1.4.3-16                                        AUR
  python-requests-cache  0.9.7-1                                         AUR
  python-tvdb_api        3.1-1                                           AUR
  tvnamer                3.0.4-1                                         AUR

So, If I understand this thread correctly, _to_bytes is gone in requests-cache 0.9.7 but this is fixed in tvdb_api 3.1-1.

Nevertheless, I still get the same error:

ImportError: cannot import name '_to_bytes' from 'requests_cache.backends.base' (/usr/lib/python3.10/site-packages/requests_cache/backends/base.py)

And it seems that this has NOT been fixed in 3.1.0:

[freddy@hades ~]$ grep -E '__version|_to_bytes' /usr/lib/python3.10/site-packages/tvdb_api.py
__version__ = "3.1.0"
from requests_cache.backends.base import _to_bytes, _DEFAULT_HEADERS
    key.update(_to_bytes(request.method.upper()))
    key.update(_to_bytes(url))
        key.update(_to_bytes(body))
                    key.update(_to_bytes(name))
                    key.update(_to_bytes(value))

So, what's going wrong here? Did I miss something?

Having the same problem :

Traceback (most recent call last):
File "/usr/bin/tvnamer", line 33, in
sys.exit(load_entry_point('tvnamer==3.0.4', 'console_scripts', 'tvnamer')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/bin/tvnamer", line 25, in importlib_load_entry_point
return next(matches).load()
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/metadata/init.py", line 202, in load
module = import_module(match.group('module'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "/usr/lib/python3.11/site-packages/tvnamer/main.py", line 18, in
import tvdb_api
File "/usr/lib/python3.11/site-packages/tvdb_api.py", line 34, in
from requests_cache.backends.base import _to_bytes, _DEFAULT_HEADERS
ImportError: cannot import name '_to_bytes' from 'requests_cache.backends.base' (/usr/lib/python3.11/site-packages/requests_cache/backends/base.py)