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.64k stars 190 forks source link

[Bug]: KeyError: 'data' in iflytek translator #126

Open ali1hammoud opened 1 year ago

ali1hammoud commented 1 year ago

Debug Tips

What happened?

I wrote this code: ts.translate_text('hello, how are you?', translator='iflytek', from_language='en', to_language='ar') ts.translate_text('hello, how are you?', translator='niutrans', from_language='en', to_language='ar')

APP Version

5.7.1

Python Version

3.10

Runtime Environment

colab google

Country/Region

Russia

Relevant log output

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-17-bdc31f9ec4ac> in <cell line: 1>()
----> 1 ts.translate_text('hello, how are you?', translator='iflytek', from_language='en', to_language='ar')

3 frames
/usr/local/lib/python3.10/dist-packages/translators/server.py in iflytek_api(self, query_text, from_language, to_language, **kwargs)
   2488         time.sleep(sleep_seconds)
   2489         self.query_count += 1
-> 2490         return data if is_detail_result else eval(data['data'])['trans_result']['dst']
   2491 
   2492 

KeyError: 'data'
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[<ipython-input-18-6bb03439ea15>](https://localhost:8080/#) in <cell line: 1>()
----> 1 ts.translate_text('hello, how are you?', translator='niutrans', from_language='en', to_language='ar')

3 frames
[/usr/local/lib/python3.10/dist-packages/translators/server.py](https://localhost:8080/#) in niutrans_api(self, query_text, from_language, to_language, **kwargs)
   3247             token_data = r_tk.json()
   3248 
-> 3249             self.account_info = {**guest_info, **token_data['data']}
   3250             self.api_headers = {**self.host_headers, **{'Jwt': self.account_info['token']}}
   3251             self.session.cookies.update({'Admin-Token': self.account_info['token']})

KeyError: 'data'

Code of Conduct

ali1hammoud commented 1 year ago

After updating to 5.7.6 I got these errors:

KeyError: 'data'

During handling of the above exception, another exception occurred:

TranslatorError                           Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/translators/server.py](https://localhost:8080/#) in _wrapper(*args, **kwargs)
    279                 raise_tips2_url = 'https://github.com/UlionTse/translators#supported-translation-services'
    280                 raise_tips2 = f'Please read for details: Status of Translator on this webpage({raise_tips2_url}).'
--> 281                 raise TranslatorError(f'{raise_tips1} {raise_tips2}')
    282         return _wrapper
    283 

TranslatorError: The function iflytek() has been not certified yet. Please read for details: Status of Translator on this webpage(https://github.com/UlionTse/translators#supported-translation-services).
KeyError: 'data'

During handling of the above exception, another exception occurred:

TranslatorError                           Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/translators/server.py](https://localhost:8080/#) in _wrapper(*args, **kwargs)
    279                 raise_tips2_url = 'https://github.com/UlionTse/translators#supported-translation-services'
    280                 raise_tips2 = f'Please read for details: Status of Translator on this webpage({raise_tips2_url}).'
--> 281                 raise TranslatorError(f'{raise_tips1} {raise_tips2}')
    282         return _wrapper
    283 

TranslatorError: The function niutrans() has been not certified yet. Please read for details: Status of Translator on this webpage(https://github.com/UlionTse/translators#supported-translation-services).

now it is clear that: The function iflytek() has been not certified yet The function niutrans() has been not certified yet

UlionTse commented 1 year ago

Hello friend! Although these functions are implemented, they have not passed the test due to various reasons, and they are in an unavailable status. This status is also marked on the README page.