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

Issues with Niutrans, Iflytek, Yandex, Alibaba #95

Closed Etile0 closed 1 year ago

Etile0 commented 2 years ago

I decided to test out all the translation services in this library and found that some of them aren't working.

First I imported the library and got some text from the example:

>>> import translators as ts
Using state Moscow server backend.
>>> a = '季姬寂,集鸡,鸡即棘鸡。棘鸡饥叽,季姬及箕稷济鸡。'

Then I started testing. This is the issue with Niutrans:

>>> ts.niutrans(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 2383, in niutrans_api
    self.account_info = {**guest_info, **token_data['data']}
KeyError: 'data'

The same error appears for Iflytech:

>>> ts.iflytek(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 1764, in iflytek_api
    return data if is_detail_result else eval(data['data'])['trans_result']['dst']
KeyError: 'data'

Yandex has a different issue. It says that the website is forbidden, although I can access it and use it just fine with my browser: ( Referenced by #94 )

>>> ts.yandex(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 1418, in yandex_api
    r.raise_for_status()
  File "/usr/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://translate.yandex.com/

Alibaba has the most complicated error:

>>> ts.alibaba(a)
Traceback (most recent call last):
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 847, in get_language_map
    return _get_lang(self.get_language_new_url, params=None)
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 842, in _get_lang
    language_map = dict(map(lambda x: x, [(x['sourceLuange'], x['targetLanguages']) for x in language_dict['languageMap']]))
KeyError: 'languageMap'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 883, in alibaba_api
    self.language_map = self.get_language_map(ss, use_domain, dmtrack_pageid, timeout, proxies)
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 849, in get_language_map
    return _get_lang(self.get_language_old_url, params=params)
  File "/home/etile/.local/lib/python3.10/site-packages/translators/apis.py", line 842, in _get_lang
    language_map = dict(map(lambda x: x, [(x['sourceLuange'], x['targetLanguages']) for x in language_dict['languageMap']]))
KeyError: 'languageMap'

I would also like to thank you for making this library. It has been a massive help in my projects.

UlionTse commented 1 year ago

@Etile0 About Niutrans, Yandex and Iflytek, please pay attention to status of readme, but thanks. About alibaba, please provide more information, such as your region about this, version, and other details (Because my test is normal).

translators_alibaba
Etile0 commented 1 year ago

Ah, I see about the first three

About alibaba, I can access it (https://translate.alibaba.com/) in my country and use it there I tried it on python3.10 and python3.8. Both didn't work so it's not my python version I am using translators==5.4.8 I also tried using a VPN to try it in Hong Kong (My VPN doesn't have Beijing unfortunately), same error.

I also use linux but that shouldn't affect it, right?

Etile0 commented 1 year ago

I decided to debug it myself a bit

When the error started, here are the values of my variables:

language_dict: {'rgv587_flag': 'sm', 'url': '/trans/acquireSupportLanguage.do/_____tmd_____/punish?x5secdata=xb09bb0c28fac753a3141f3473d4a039fc1667634964a2025037794a560717130abazc2aaa__bx__translate.alibaba.com%3A443%2Ftrans%2FacquireSupportLanguage.do&x5step=2'} language_url: 'https://translate.alibaba.com/trans/acquireSupportLanguage.do' params: {'dmtrack_pageid': '00118446ca280724cb54cb217c29813dcb9db87c7c', 'biz_type': 'message'}

I would be willing to provide any other data that you need

UlionTse commented 1 year ago

@Etile0 Can you access this link: https://translate.alibaba.com/translationopenseviceapp/trans/acquire_supportLanguage.do

Etile0 commented 1 year ago

Yes, I can

image

UlionTse commented 1 year ago

From your pictures, we can see that the data we get from the same links are inconsistent. I think it may be caused by these two problems. One is the geographical location of the source and the other is the physical machine that accesses the source. Therefore, you can test as follows:

  1. Physical machine related: What is your Linux system, and does it contain a desktop or browser?
  2. Geographic location: The geographic location where your server or physical machine accesses
  3. Counterevidence: Find a home Windows or Mac computer to try to access
translators_alibaba_apipost
Etile0 commented 1 year ago

Sorry for not replying, I was a bit busy

I found a VPN in China and, even when I use that, it doesn't work

To answer your questions:

  1. I use arch and it has a desktop and browser (both firefox and chromium)
  2. I tried from Moscow, Russia; Guangdong, China; Central and Western District, Hong Kong
  3. This shouldn't matter, but I'll try it in a bit

I get the same error from every location I try. I also tried from 3 different linux systems: my home computer (arch), my laptop (also arch) and my vps (ubuntu). All also have the same error

UlionTse commented 1 year ago

@Etile0 Hello friend I just updated the new alibaba version, as well as debug_language_map, you can pip the newest and try it again.

Etile0 commented 1 year ago

Just tested, it works now, thank you!