Saigesp / json-translate

Translate json files with DeepL or AWS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP Error 403: Forbidden

antonkarliner opened this issue · comments

Hello! Thanks for fixing #28, I'm no longer having this error, however, now there's another one:
json_translate deepl files/recipes_wilfa.json RU
Traceback (most recent call last):
File "/opt/homebrew/bin/json_translate", line 8, in
sys.exit(main())
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/commands.py", line 51, in main
results = translator.translate(
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 54, in translate
return self._iterate_over_keys(data)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 68, in _iterate_over_keys
return [self._iterate_over_keys(value) for value in data]
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 68, in
return [self._iterate_over_keys(value) for value in data]
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
return self._get_dict_iteration(data)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
result[key] = self._iterate_over_keys(value)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 72, in _iterate_over_keys
return self._get_string_iteration(data)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 100, in _get_string_iteration
result = self.translate_string(text)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/deepl.py", line 43, in translate_string
response = request.urlopen(req) # nosec
File "/opt/homebrew/Cellar/python@3.10/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/opt/homebrew/Cellar/python@3.10/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 525, in open
response = meth(req, response)
File "/opt/homebrew/Cellar/python@3.10/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 634, in http_response
response = self.parent.error(
File "/opt/homebrew/Cellar/python@3.10/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 563, in error
return self._call_chain(*args)
File "/opt/homebrew/Cellar/python@3.10/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/opt/homebrew/Cellar/python@3.10/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Hi @antonkarliner,

According to the DeepL documentation, your auth key may be wrong:

How can I avoid error 403, "Authorization failed. Please supply a valid auth_key parameter"?

This error occurs when the authentication key in the request is either missing or incorrect.

https://support.deepl.com/hc/en-us/articles/360020031840-Error-code-403

getting the same error even though this curl runs just fine with my api key:

curl -X POST 'https://api-free.deepl.com/v2/translate' \                                                                                                                                                                                                                        1 х  at 22:43:04 
--header 'Authorization: DeepL-Auth-Key xxx-xxxx-xxxx:fx' \
--data-urlencode 'text=Hello, world!' \
--data-urlencode 'target_lang=DE'

It seems that the script fails to get the .env DEEPL_AUTH_KEY.

solution:

run this in terminal:

macos: export DEEPL_AUTH_KEY=paste_your_key_here

or

windows: set DEEPL_AUTH_KEY=paste_your_key_here

then run thejson_translate xxxxx and it should work