Animenosekai / translate

A module grouping multiple translation APIs
GNU Affero General Public License v3.0
525 stars 60 forks source link

example() not working #77

Open Faizan-E-Mustafa opened 1 year ago

Faizan-E-Mustafa commented 1 year ago

The example function is not working. First, I use the following code

from translatepy import Translator
translate = Translator()

print(translate.example("Hello", "German", "English"))

which gives the following error.

Traceback (most recent call last):
  File "C:\Users\femustafa\Desktop\Language app\main.py", line 81, in <module>
    print(translate.example("Hello", "German", "English"))
  File "C:\Users\femustafa\Desktop\Language app\.venv\lib\site-packages\translatepy\translate.py", line 363, in example
    raise NoResult("No service has returned a valid result")
translatepy.exceptions.NoResult: No service has returned a valid result

As example function is not implemented for all translators. I just use Bing translator

from translatepy.translators.bing import BingTranslate
translate = BingTranslate()

print(translate.example("Hello", "German", "English"))

which gives the following error.

Traceback (most recent call last):
  File "C:\Users\femustafa\Desktop\Language app\main.py", line 81, in <module>
    print(translate.translate("Hello", "German", "English"))
  File "C:\Users\femustafa\Desktop\Language app\.venv\lib\site-packages\translatepy\translators\base.py", line 110, in translate 
    source_language, translation = self._translate(text, dest_code, source_code)
  File "C:\Users\femustafa\Desktop\Language app\.venv\lib\site-packages\translatepy\translators\bing.py", line 156, in _translate    response = self.session_manager.send("https://www.bing.com/ttranslatev3", data={'text': text, 'fromLang': source_language, 'to': destination_language})
  File "C:\Users\femustafa\Desktop\Language app\.venv\lib\site-packages\translatepy\translators\bing.py", line 135, in send      
    raise BingTranslateException(status_code)
translatepy.translators.bing.BingTranslateException: 205 | Unknown error. Error code: 205

Am i doing something wrong? . Your help will be appreciated.

ZhymabekRoman commented 1 year ago

Yes, this is a problem that we should work on. Some thoughts about the example method refactor is there: https://github.com/Animenosekai/translate/discussions/62