Skip to content

[Bug]: KeyError: 'data' when using baidu #146

@Old-Farmer

Description

@Old-Farmer

Debug Tips

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

What happened?

I run this code.

import translators

proxies = {"https": "http://127.0.0.1:7890/"}
# proxies = {}

text = translators.translate_text(
    query_text="i have a pen",
    from_language="en",
    to_language="zh",
    translator="baidu",
    proxies=proxies,
)
print(text)

I am sure this proxy is right.

Then I get this output:

Using region Central and Western District server backend.

Traceback (most recent call last):
  File "/home/shixinchai/mine/projects/Utils/dict/./new.py", line 536, in <module>
    text = translators.translate_text(
  File "/home/shixinchai/.local/lib/python3.10/site-packages/translators/server.py", line 5294, in translate_text
    return self.translators_dict[translator](query_text=query_text, from_language=from_language, to_language=to_language, **kwargs)
  File "/home/shixinchai/.local/lib/python3.10/site-packages/translators/server.py", line 104, in _wrapper
    return func(*args, **kwargs)
  File "/home/shixinchai/.local/lib/python3.10/site-packages/translators/server.py", line 273, in _wrapper
    return func(*args, **{**kwargs, **{'query_text': query_text}})
  File "/home/shixinchai/.local/lib/python3.10/site-packages/translators/server.py", line 718, in baidu_api
    return data if is_detail_result else '\n'.join([item['dst'] for item in data['data']])
KeyError: 'data'

However, if I set from_language as "auto", everything works fine.

APP Version

translators v5.8.7

Python Version

3.10

Runtime Environment

Linux Ubuntu

Country/Region

Central and Western District

Relevant log output

No response

Screenshots

No response

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