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.66k stars 193 forks source link

[Bug]: The `query_text` can't be empty! raise error on Html content #107

Closed NicoloCipiti closed 1 year ago

NicoloCipiti commented 1 year ago

Debug Tips

What happened?

When feeding translate_html() function with actual html code, it always raise Thequery_textcan't be empty! error

APP Version

3

Python Version

3.10

Runtime Environment

MacOS

Country/Region

Italy

Relevant log output

Running test.py after cloning the repo gives the following:

Using state Lombardy server backend.
multiprocess.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/multiprocess/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/lib/python3.10/site-packages/multiprocess/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/usr/local/lib/python3.10/site-packages/pathos/helpers/mp_helper.py", line 15, in <lambda>
    func = lambda args: f(*args)
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/server.py", line 3051, in <lambda>
    _map_translate_func = lambda sentence: (sentence, _ts(query_text=sentence, from_language=from_language, to_language=to_language, **kwargs))
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/server.py", line 98, in _wrapper
    return func(*args, **kwargs)
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/server.py", line 217, in _wrapper
    query_text = check_query_text(query_text, if_ignore_empty_query, if_ignore_limit_of_length, limit_of_length)
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/server.py", line 199, in check_query_text
    raise TranslatorError("The `query_text` can't be empty!")
server.TranslatorError: The `query_text` can't be empty!
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/test.py", line 83, in <module>
    test0()
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/test.py", line 51, in test0
    r = translate_html(html_text, to_language='zh', translator=translators_pool[0], n_jobs=4)
  File "/Users/nico/Desktop/SERVER/Hoculus-Python-Bots/translators/translators/server.py", line 3054, in translate_html
    result_list = pool.map(_map_translate_func, sentence_list)
  File "/usr/local/lib/python3.10/site-packages/pathos/multiprocessing.py", line 135, in map
    return _pool.map(star(f), zip(*args)) # chunksize
  File "/usr/local/lib/python3.10/site-packages/multiprocess/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/usr/local/lib/python3.10/site-packages/multiprocess/pool.py", line 774, in get
    raise self._value
server.TranslatorError: The `query_text` can't be empty!

Screenshots

![DESCRIPTION](LINK.png)

Code of Conduct

UlionTse commented 1 year ago

Please use parameter if_ignore_empty_query=True.