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

Encoder does not support base type - None #15

Open
CrazyLionHeart opened this issue May 27, 2020 · 2 comments
Open

Encoder does not support base type - None #15

CrazyLionHeart opened this issue May 27, 2020 · 2 comments

Comments

@CrazyLionHeart
Copy link

Version: bencode.py==2.1.0

Test:

bencode.bencode(None)

expected: b'0:'
actual:

>>> bencode.bencode(None)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "./.env/lib/python3.8/site-packages/bencode/__init__.py", line 304, in bencode
   encode_func[type(value)](value, r)
KeyError: <class 'NoneType'>
@fuzeman
Copy link
Owner

fuzeman commented May 28, 2020

I'm not sure how we should be handling types not listed in the bencode specification. Internal type conversions that aren't reversible might not be expected by some users (bool and tuple also have this issue).

Moving forward maybe there should be a flag or separate method to use type conversions?


expected: b'0:'

Not sure encoding None to an empty string is the best option here. Would b'i0e' (0, False) be a better fit?

@cisene
Copy link

cisene commented Jul 11, 2023

Stumbled upon "KeyError: <class 'float'>" and added code to handle data of type FLOAT.

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

No branches or pull requests

3 participants