Skip to content

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

@ali1hammoud

Description

@ali1hammoud

Debug Tips

  • I'm sure I've read this project's Issues of README.

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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions