deepl-alfred-workflow2 icon indicating copy to clipboard operation
deepl-alfred-workflow2 copied to clipboard

Random error - JSON Parse error: Unexpected identifier "undefined" (-2700)

Open strangerinusall opened this issue 1 year ago • 5 comments

Hi! Thanks for making this workflow!

I have one issue - when I enter my word(s) to be translated it sometimes gives 'error' in the Alfred output. I did some testing and couldn't find a pattern, since it sometimes gives error and sometimes not for the same exact word(s). This is from Alfred's debugger:

[08:26:08.974] ERROR: Deepl-Translate[Script Filter] Code 8: curl -s 'https://www2.deepl.com/jsonrpc' '--compressed -H authority: www2.deepl.com -H Origin: https://www.deepl.com -H Referer: https://www.deepl.com/translator -H Accept: / -H Content-Type: application/json -H Accept-Language: en-us -H User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15' --data-binary $'{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"commonJobParams": {"browserType": 1, "mode": "translate", "textType": "plaintext"}, "jobs":[{"kind":"default","raw_en_sentence":"hi","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["EN"],"source_lang_user_selected":"auto","target_lang":"en"},"priority":1,"timestamp":1557063997314},"id":79120002}' execution error: Error: SyntaxError: JSON Parse error: Unexpected identifier "undefined" (-2700)

strangerinusall avatar Oct 31 '24 08:10 strangerinusall

me too

cha0ran avatar Jun 12 '25 05:06 cha0ran

Mh, ok, when this happens the API does not return a valid JSON - for a currently unknown reason. I've uploaded a modified version (cf0cbcd, no release yet) that checks if the response is valid JSON and returns a proper error message to Alfred. This might help to understand what is going on. So if you feel comfortable, replace the code with https://github.com/AlexanderWillner/deepl-alfred-workflow2/blob/master/deepl.sh and let us know when this issue happens again.

AlexanderWillner avatar Jun 13 '25 16:06 AlexanderWillner

[10:30:57.802] ERROR: Deepl-Translate[Script Filter] Code 8: curl -s 'https://www2.deepl.com/jsonrpc' '--compressed -H authority: www2.deepl.com -H Origin: https://www.deepl.com -H Referer: https://www.deepl.com/translator -H Accept: */* -H Content-Type: application/json -H Accept-Language: en-us -H User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15' --data-binary $'{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"commonJobParams": {"browserType": 1, "mode": "translate", "textType": "plaintext"}, "jobs":[{"kind":"default","raw_en_sentence":"hello everyone","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["ZH", "EN"],"source_lang_user_selected":"auto","target_lang":"ZH"},"priority":1,"timestamp":1557063997314},"id":79120002}'
DEBUG: curl exit code: 0
DEBUG: result length: 73
DEBUG: result first 200 chars: {"jsonrpc":"2.0","error":{"code":1042912,"message":"Too many requests"}}
[10:30:57.802] Deepl-Translate[Script Filter] {"items": [{"uid": null,"arg": "Error: Too many requests","valid": "yes","autocomplete": "autocomplete","title": "Error: Too many requests"}]}

This is the new error message I received. It seems that the request has been restricted due to excessive requests?

cha0ran avatar Jun 14 '25 02:06 cha0ran

Can you avoid this issue following this procedure?

  • Invoke Alfred
  • Press ⌘ + ,
  • Go to Workflows
  • Right click on DeepL-Translate > Configure...
  • Enter the API Key you got from DeepL for free

AlexanderWillner avatar Jun 14 '25 21:06 AlexanderWillner

Sadly, DeepL doesn't support the region where I'm located, so I can't get an API key.

cha0ran avatar Jun 15 '25 00:06 cha0ran