Ask Your Question
0

How can I fix requests.exceptions.HTTPError: 404 Client Error: Not Found for google_trans_new?

asked 2023-04-25 19:47:03 +0000

wagner gravatar image

updated 2023-04-26 14:21:47 +0000

I am getting the error below when trying to translate a text with google_trans_new in Python:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/googletransnew/googletransnew.py", line 189, in translate r.raiseforstatus() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raiseforstatus raise HTTPError(httperrormsg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https:// translate .google .cn/_/TranslateWebserverUi/data/batchexecute

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test.py", line 9, in <module> translation = translator.translate(text, langtgt=targetlanguage) File "/usr/local/lib/python3.10/dist-packages/googletransnew/googletransnew.py", line 194, in translate raise googlenewtransError(tts=self, response=r) googletransnew.googletransnew.googlenewtransError: 404 (Not Found) from TTS API. Probable cause: Unknown

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-25 19:49:27 +0000

wagner gravatar image

updated 2023-04-26 14:34:27 +0000

It turned out that the following patch fixes the problem. If you installed the package via git, you need implement the changes directly in the google_trans_new.py in your Python site-packages location:

https://github.com/lushan88a/google_trans_new/pull/58/commits/aa4faaa9c322e8772e6a1cbad472e94af7405d64

After applying the fix you can translate a text like follows:

from google_trans_new import google_translator

# Text to translate
text = "Hello, how are you?"

target_language = "es"
translator = google_translator()
translation = translator.translate(text, lang_tgt=target_language)

print(f"Original text: {text}")
print(f"Translation: {translation}")
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

1 follower

Stats

Asked: 2023-04-25 19:47:03 +0000

Seen: 67 times

Last updated: Apr 26 '23