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]: translator server - google: language map is empty so getting error "Unsupported from_language[ar] in []" #144

Closed SteniMariyaThomas closed 11 months ago

SteniMariyaThomas commented 11 months ago

Debug Tips

What happened?

While translating an arabic content to english using translator server: google, I am getting error

Unsupported from_language[ar] in []

On further research I found that language_map is getting as empty.

And urllib.parse.urlparse(r.url).hostname is consent.google.com. Based on that while getting consent cookie input_element is empty input_element = et.xpath('.//input[@type="hidden"][@name="v"]')

It was working previously. Now failing to translate due to this error. I am using latest version of translators

Any help will be greatly appreciated!

APP Version

0.0.1(example)

Python Version

3.9 (Default)

Runtime Environment

Linux CentOS (Default)

Country/Region

Dubai

Relevant log output

No response

Screenshots

![DESCRIPTION](LINK.png)

Code of Conduct

Cabu commented 11 months ago

See #142

UlionTse commented 11 months ago

@SteniMariyaThomas Hello friend, please give me more error information! Whether the version is 5.8.3 or not?

translators_20230919
SteniMariyaThomas commented 11 months ago

@UlionTse Yes the version is 5.8.3. Issue exists in previous version also

UlionTse commented 11 months ago

@SteniMariyaThomas Try ts.get_languages('google'). Whether you made a high-frequency request, or first request shows error?

ManuelSchneid3r commented 11 months ago
>>> import translators as ts
>>> ts.get_languages('google')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.11/site-packages/translators/server.py", line 5204, in get_languages
    _ = self._test_translate(_ts=translator)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/translators/server.py", line 5188, in _test_translate
    result = self.translators_dict[_ts](
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/translators/server.py", line 104, in _wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/translators/server.py", line 261, in _wrapper
    return func(*args, **{**kwargs, **{'query_text': query_text}})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/translators/server.py", line 599, in google_api
    from_language, to_language = self.check_language(from_language, to_language, self.language_map, output_zh=self.output_zh)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/translators/server.py", line 174, in check_language
    raise TranslatorError('Unsupported to_language[{}] in {}.'.format(to_language, sorted(language_map.keys())))
translators.server.TranslatorError: Unsupported to_language[en] in [].
UlionTse commented 11 months ago

@ManuelSchneid3r Bro, you should update version, v5.8.5 shouldn't show errors like yours.

ManuelSchneid3r commented 11 months ago
>>> ts.__version__
'5.8.5'
>>> ts.get_languages('google')
{'auto': 'en', 'zh-CN': 'en', 'en': 'zh-CN'}
SteniMariyaThomas commented 11 months ago

@SteniMariyaThomas Hello friend, please give me more error information! Whether the version is 5.8.3 or not? translators_20230919

Its 5.8.3

UlionTse commented 11 months ago

@ManuelSchneid3r Why? Which country or region are you in? Is it because Google offers different services in different regions?

translators20230927
UlionTse commented 11 months ago

@ManuelSchneid3r Can you send me your host_html about https://translate.google.com, my email is uliontse@outlook.com, thanks.

SteniMariyaThomas commented 11 months ago

@SteniMariyaThomas Try ts.get_languages('google'). Whether you made a high-frequency request, or first request shows error?

both cases

UlionTse commented 11 months ago

@ManuelSchneid3r Why? Which country or region are you in? Is it because Google offers different services in different regions? translators20230927

@SteniMariyaThomas Same question.

UlionTse commented 11 months ago

@ManuelSchneid3r Can you send me your host_html about https://translate.google.com, my email is uliontse@outlook.com, thanks.

@SteniMariyaThomas Both helps.

UlionTse commented 11 months ago

@SteniMariyaThomas Try ts.get_languages('google'). Whether you made a high-frequency request, or first request shows error?

both cases

@ManuelSchneid3r high-frequency request, and you?

ManuelSchneid3r commented 11 months ago

Nope, single request from python shell

ManuelSchneid3r commented 11 months ago

@ManuelSchneid3r Can you send me your host_html about https://translate.google.com, my email is uliontse@outlook.com, thanks.

How can I obtain the host_html? You mean the website source code?

UlionTse commented 11 months ago

@ManuelSchneid3r Can you send me your host_html about https://translate.google.com, my email is uliontse@outlook.com, thanks.

How can I obtain the host_html? You mean the website source code?

@ManuelSchneid3r Yeah.

ManuelSchneid3r commented 11 months ago

Google Übersetzer.html.zip

ManuelSchneid3r commented 11 months ago

btw bavaria backend was chosen (germany)

UlionTse commented 11 months ago

@ManuelSchneid3r Thanks for your html, bro. But look at this, you can get_languages('google').

translators20230930v2
UlionTse commented 11 months ago

142 Same reason?

ManuelSchneid3r commented 11 months ago

I dont know where the problem stems from, but its still …


>>> import translators as ts
>>> ts.__version__
'5.8.5'
>>> ts.get_languages('google')
{'auto': 'en', 'zh-CN': 'en', 'en': 'zh-CN'}
UlionTse commented 11 months ago

@ManuelSchneid3r @Cabu Bros, please pip install --upgrade translators==5.8.6.

ManuelSchneid3r commented 10 months ago

works, ty 👍