Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
Old-Farmer opened this issue Nov 5, 2023 · 2 comments
Open
2 tasks done

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

Old-Farmer opened this issue Nov 5, 2023 · 2 comments
Assignees

Comments

@Old-Farmer
Copy link

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
@UlionTse
Copy link
Owner

UlionTse commented Nov 6, 2023

@Old-Farmer It's not a proxy problem, you try setting from_language to auto and it should be fine. Then you try to use longer sentences and then change the from_language and it doesn't seem to be a problem. Therefore, I do not know how this problem is handled within the translation service.
By the way, pip install --upgrade translators==5.8.8

@Touch-Night
Copy link

Try changing self._baidu = BaiduV1() # V2 to V2. V1 doesn't work anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants