Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name '_to_bytes' #92

Closed
gene1wood opened this issue Apr 15, 2021 · 4 comments · Fixed by #93
Closed

ImportError: cannot import name '_to_bytes' #92

gene1wood opened this issue Apr 15, 2021 · 4 comments · Fixed by #93

Comments

@gene1wood
Copy link
Contributor

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

@marukuru
Copy link

Temporary fix: pip install requests-cache==0.5.0

gene1wood added a commit to gene1wood/tvdb_api that referenced this issue Apr 29, 2021
This constrains the requests-cache package to a version older than
0.6.0[1] in which the `_to_bytes` method was removed. This method is
used[2] in tvdb_api. Once use of the `_to_bytes` methods is removed
from tvdb_api, this version contraint can be removed.

Fixes dbr#92

[1]: https://github.com/reclosedev/requests-cache/blob/master/HISTORY.md#060-2021-04-09
[2]: https://github.com/dbr/tvdb_api/blob/92e8c7cdf5bc1d923f9ed97dacbfd2b52bb4c893/tvdb_api.py
@dbr dbr closed this as completed in #93 Apr 29, 2021
@dbr
Copy link
Owner

dbr commented Apr 29, 2021

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

@frank42hh
Copy link

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?

@Revdep
Copy link

Revdep commented Apr 4, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants