UlionTse / translators

🌏🌍🌎Translators🌎🌍🌏 is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python. Translators是一个旨在用Python为个人和学生带来免费、多样、愉快翻译的库。
https://pypi.org/project/translators/
GNU General Public License v3.0
1.62k stars 189 forks source link

[Bug]: crash #154

Closed 6801318d8d closed 6 months ago

6801318d8d commented 6 months ago

Debug Tips

What happened?

Exception

APP Version

5.8.9

Python Version

3.11

Runtime Environment

Other

Country/Region

Italy

Relevant log output

Python version is 3.12.1, but this version is not available in the select box.

OS is Arch Linux, but this OS is not available in the select box.

The following code:

#!/usr/bin/env python
import translators as ts

with open("debug.txt", "r") as fh:
    data = fh.read()

dataout = ts.translate_text(
    data,
    translator="google",
    from_language="auto",
    to_language="en",
)
print(dataout)

With file input.txt generated the following exception:

Traceback (most recent call last):
  File "/home/USERNAME/Dropbox (Maestral)/papers/paper_6_RM/src/2_translate/./bugrep.py", line 7, in <module>
    dataout = ts.translate_text(
              ^^^^^^^^^^^^^^^^^^
  File "/home/USERNAME/.pyenv/versions/translators/lib/python3.12/site-packages/translators/server.py", line 5312, in translate_text
    return self.translators_dict[translator](query_text=query_text, from_language=from_language, to_language=to_language, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/USERNAME/.pyenv/versions/translators/lib/python3.12/site-packages/translators/server.py", line 104, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/USERNAME/.pyenv/versions/translators/lib/python3.12/site-packages/translators/server.py", line 273, in _wrapper
    return func(*args, **{**kwargs, **{'query_text': query_text}})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/USERNAME/.pyenv/versions/translators/lib/python3.12/site-packages/translators/server.py", line 623, in google_api
    data = json.loads(json_data[0][2])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/USERNAME/.pyenv/versions/3.12.1/lib/python3.12/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

Code of Conduct

UlionTse commented 6 months ago

@6801318d8d Hello friend! You need more shorter input_text, <=4995.

translators_154
6801318d8d commented 6 months ago

Hello,

Thank you very much for the answer.

Where did you find this condition, input_text <=4995?

Is it written in the README? Is it written in the error log?

UlionTse commented 6 months ago

A result of constant testing. The official theoretical value is 5,000.