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

fix error with float32 error with json.dumps in server mode #13

Open
Aprilistic opened this issue Aug 16, 2024 · 1 comment · May be fixed by #14
Open

fix error with float32 error with json.dumps in server mode #13

Aprilistic opened this issue Aug 16, 2024 · 1 comment · May be fixed by #14

Comments

@Aprilistic
Copy link

Hi there!

I found that when I use langid in server mode langid -s, and send a request curl -d "q=This is a test" localhost:9008/detect I get an error with json.dumps because of its compatibility with float32.

This error also happens with the original langid code but the repo hasn't been updated for a while.

So, I added a custom encoder to prevent the error, which works well now.
You can find how I changed it in this commit log.
master...Aprilistic:py3langid:master

Error log
File "/opt/homebrew/Caskroom/miniforge/base/envs/test/lib/python3.12/site-packages/py3langid/langid.py", line 352, in application return [json.dumps(response)] ^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/test/lib/python3.12/json/__init__.py", line 231, in dumps return _default_encoder.encode(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/test/lib/python3.12/json/encoder.py", line 200, in encode chunks = self.iterencode(o, _one_shot=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/test/lib/python3.12/json/encoder.py", line 258, in iterencode return _iterencode(o, 0) ^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/test/lib/python3.12/json/encoder.py", line 180, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type float32 is not JSON serializable

@adbar adbar linked a pull request Oct 1, 2024 that will close this issue
@adbar
Copy link
Owner

adbar commented Oct 1, 2024

@Aprilistic Thank you for describing the bug and suggesting a solution.

I just decided to use the commit you mentioned in a pull request. Do you have anything to add?

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.

2 participants