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.62k stars 189 forks source link

[Bug]: deepl is not stable #116

Open diwert-ai opened 1 year ago

diwert-ai commented 1 year ago

Debug Tips

What happened?

Deepl is not stable. Sometimes it works fine, sometimes it gives an error (see below)

APP Version

5.5.6

Python Version

=3.6, <=3.8

Runtime Environment

Linux Ubuntu

Country/Region

US

Relevant log output

import translators as ts
print(ts.translate_text(query_text='To be, or not to be, that is the question!', to_language='ru',  translator='deepl'))

output:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-6-428c3aab60d7> in <module>
      1 import translators as ts
      2 #import translators.server as tss
----> 3 print(ts.translate_text(query_text='To be, or not to be, that is the question!', to_language='ru',  translator='deepl'))

4 frames
/usr/local/lib/python3.8/dist-packages/translators/server.py in translate_text(self, query_text, translator, from_language, to_language, **kwargs)
   3113         if translator not in self.translators_pool:
   3114             raise TranslatorError
-> 3115         return self.translators_dict[translator](query_text=query_text, from_language=from_language, to_language=to_language, **kwargs)
   3116 
   3117     def translate_html(self,

/usr/local/lib/python3.8/dist-packages/translators/server.py in _wrapper(*args, **kwargs)
     96                 sys.stderr.write(f'CostTime(function: {func.__name__[:-4]}): {cost_time}s\n')
     97                 return result
---> 98             return func(*args, **kwargs)
     99         return _wrapper
    100 

/usr/local/lib/python3.8/dist-packages/translators/server.py in _wrapper(*args, **kwargs)
    223                 new_args[1] = query_text
    224                 return func(*tuple(new_args), **kwargs)
--> 225             return func(*args, **{**kwargs, **{'query_text': query_text}})
    226         return _wrapper
    227 

/usr/local/lib/python3.8/dist-packages/translators/server.py in deepl_api(self, query_text, from_language, to_language, **kwargs)
   1768 
   1769         r_cs = self.session.post(self.api_url, params=self.params['handle'], json=h_data, headers=self.api_headers, timeout=timeout, proxies=proxies)
-> 1770         r_cs.raise_for_status()
   1771         data = r_cs.json()
   1772         time.sleep(sleep_seconds)

/usr/local/lib/python3.8/dist-packages/requests/models.py in raise_for_status(self)
   1019 
   1020         if http_error_msg:
-> 1021             raise HTTPError(http_error_msg, response=self)
   1022 
   1023     def close(self):

HTTPError: 429 Client Error:  for url: https://www2.deepl.com/jsonrpc?method=LMT_handle_jobs

### Screenshots

```Markdown
![DESCRIPTION](LINK.png)

Code of Conduct

UlionTse commented 1 year ago

@diwert-ai Yeah. At some point deepl will trigger a captcha, and api requests without captcha validation will be forbidden.

reddere commented 12 months ago

Is there any fix to this?

UlionTse commented 11 months ago

@reddere Not yet

UlionTse commented 11 months ago

@reddere Bro, please try pip install --upgrade translators==5.8.7