Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script with argv '(null)' finished #29

Closed
gmdelisle opened this issue Nov 15, 2023 · 21 comments
Closed

Script with argv '(null)' finished #29

gmdelisle opened this issue Nov 15, 2023 · 21 comments

Comments

@gmdelisle
Copy link

Hi!
Thank you for this workflow.
My problem. Fresh install. Only copied the DeepL API key.
If I type "nein" just to test, nothing comes up. Same with all words.
I get this error in the debugger.

Deepl-Translate[Script Filter] Queuing argument 'nein'
Deepl-Translate[Script Filter] Script with argv '(null)' finished

Thanks in advance.

@Odaeus
Copy link

Odaeus commented Nov 21, 2023

Came here to report that I have the same error in the debugger except instead of nothing, it shows the word I entered back to me without translation.

@AlexanderWillner
Copy link
Owner

  • I see the same behaviour here
  • It's not an issue with the underlying scripts or the API
  • actually, you've to configure what you want to translate in the environment variables (workflow > (x) > Environment Variables)
  • by default it translates to english
[13:43:41.581] Deepl-Translate[Script Filter] Queuing argument 'Nein.'
[13:43:41.936] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[13:43:41.947] Deepl-Translate[Script Filter] {
  "items": [
    {
      "uid": null,
      "arg": "No",
      "valid": "yes",
      "autocomplete": "autocomplete",
      "title": "No"
    }
  ]
}
image

@gmdelisle
Copy link
Author

gmdelisle commented Dec 3, 2023

Yes I have all that configured on the workflow's configuration complete with my Deepl Key.

SCR-20231203-lvek

If I add these values as Environment variables as well I get a warning from Alfred.
SCR-20231203-lwaa

I tried erasing everything in the Configuration builder and use only Environment variables to no avail.
Using Alfred 5.1.4, Alfred 5 workflow v1.11.

@AlexanderWillner
Copy link
Owner

Got it, workflow v1.9 was working, v1.11 is not...I've to check the underlying issue.

@AlexanderWillner
Copy link
Owner

Ok, I guess I found it.

  1. What if you press return?
  2. What if you use the keyword dl-to-en instead?

@gmdelisle
Copy link
Author

gmdelisle commented Dec 12, 2023

Hi,
I really appreciate the follow-up!

I'm sorry to report that I have the same issue.
Still get the same Output, but now with added error about jq.
Using Alfred 5.1.4, Alfred 5 workflow v1.13.

Deepl-Translate[Script Filter] Queuing argument 'nein' Deepl-Translate[Script Filter] Script with argv '(null)' finished ERROR: Deepl-Translate[Script Filter] Code 1: Binary 'jq' not found. Install it via 'brew install jq'.

Installed Homebrew and JQ just to be sure. Still the same.

@AlexanderWillner
Copy link
Owner

OK, then the issue is clear. Version 2.0.0 (just released) should fix this.

@gmdelisle
Copy link
Author

High-five for a quick response! Wow. 🙏

Same issue here.
FYI not experiencing any other issues with other workflows.

This time getting a slightly different error.

[23:57:20.471] Deepl-Translate[Script Filter] Queuing argument 'nein.'
[23:57:21.040] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[23:57:21.050] ERROR: Deepl-Translate[Script Filter] Code 1: execution error: Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700)

Config is default. Have tried removing my DeelL API key to no avail. If ever there are steps you want me to try, let me know.
image

Appreciate the help.

@AlexanderWillner
Copy link
Owner

Ok, let's find the issue:

  1. Go to Alfred settings > Workflows > Deepl-Translate > right click > Open in Terminal
  2. Run bash -x deepl.sh -l EN "nein."
  3. Copy and paste the output here

@gmdelisle
Copy link
Author

Here you go!
Hope this helps you see what the problem is.

+ LANGUAGE=EN
+ LANGUAGE_SOURCE=auto
+ LANGUAGE_PREFERRED='["DE","EN"]'
+ KEY=
+ PRO=
+ POSTFIX=.
+ VERSION=2.0
+ PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin/
+++ dirname deepl.sh
++ cd .
++ pwd
+ DIR='/Users/macos/Library/CloudStorage/Dropbox/Préférences Alfred/Alfred.alfredpreferences/workflows/user.workflow.8E688CE1-8565-45D9-944F-7C43DF4CD1E2'
+ POSITIONAL=()
+ [[ 3 -gt 0 ]]
+ key=-l
+ case "$key" in
+ LANGUAGE=EN
+ shift
+ shift
+ [[ 1 -gt 0 ]]
+ key=nein.
+ case "$key" in
+ POSITIONAL+=("$1")
+ shift
+ [[ 0 -gt 0 ]]
+ set -- nein.
+ '[' -z nein. ']'
+ query=nein.
++ echo nein.
++ sed 's/\"/\\\"/g'
+ query=nein.
++ echo nein.
++ sed 's/'\''/\\'\''/g'
+ query=nein.
++ echo nein.
++ iconv -f utf-8-mac -t utf-8
++ xargs
+ query=nein.
+ [[ '' = '' ]]
+ [[ nein. != *\. ]]
++ echo nein.
++ sed 's/\.$//'
+ query=nein
+ data='{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"nein","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ HEADER=(--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')
+ '[' -n '' ']'
++ 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":{"jobs":[{"kind":"default","raw_en_sentence":"nein","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ result='{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"nein","num_symbols":3}],"quality":"normal"}],"target_lang":"EN","source_lang":"EN","source_lang_is_confident":false,"detectedLanguages":{"EN":0.020787,"DE":0.040136,"FR":0.011696999999999999,"ES":0.01813,"PT":0.010837,"IT":0.011158,"NL":0.028071,"PL":0.011411,"RU":0.012218,"ZH":0.010069999999999999,"JA":0.011035999999999999,"BG":0.009132999999999999,"CS":0.020419,"DA":0.020047,"EL":0.008643,"ET":0.007956999999999999,"FI":0.026715,"HU":0.014846999999999999,"LT":0.014365,"LV":0.012298,"RO":0.016255,"SK":0.013446999999999999,"SL":0.015749,"SV":0.01452,"TR":0.008945999999999999,"ID":0.013646,"UK":0.01048,"KO":0.0'883,"NB":0.019434,"unsupported":0.5587179999999999}}}
+ [[ {"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"nein","num_symbols":3}],"quality":"normal"}],"target_lang":"EN","source_lang":"EN","source_lang_is_confident":false,"detectedLanguages":{"EN":0.020787,"DE":0.040136,"FR":0.011696999999999999,"ES":0.01813,"PT":0.010837,"IT":0.011158,"NL":0.028071,"PL":0.011411,"RU":0.012218,"ZH":0.010069999999999999,"JA":0.011035999999999999,"BG":0.009132999999999999,"CS":0.020419,"DA":0.020047,"EL":0.008643,"ET":0.007956999999999999,"FI":0.026715,"HU":0.014846999999999999,"LT":0.014365,"LV":0.012298,"RO":0.016255,"SK":0.013446999999999999,"SL":0.015749,"SV":0.01452,"TR":0.008945999999999999,"ID":0.013646,"UK":0.01048,"KO":0.00883, == *\"\e\r\r\o\r\"\:\{\"\c\o\d\e\"\:* ]]99999}}}
+ osascript -l JavaScript -e 'function run(argv) {
      const translations = JSON.parse(argv[0])["result"]["translations"][0]["beams"].map(item => ({
        title: item["postprocessed_sentence"],
        arg: item["postprocessed_sentence"]
      }))

      return JSON.stringify({ items: translations }, null, 2)
    }' '{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"nein","num_symbols":3}],"quality":"normal"}],"target_lang":"EN","source_lang":"EN","source_lang_is_confident":false,"detectedLanguages":{"EN":0.020787,"DE":0.040136,"FR":0.011696999999999999,"ES":0.01813,"PT":0.010837,"IT":0.011158,"NL":0.028071,"PL":0.011411,"RU":0.012218,"ZH":0.010069999999999999,"JA":0.011035999999999999,"BG":0.009132999999999999,"CS":0.020419,"DA":0.020047,"EL":0.008643,"ET":0.007956999999999999,"FI":0.026715,"HU":0.014846999999999999,"LT":0.014365,"LV":0.012298,"RO":0.016255,"SK":0.013446999999999999,"SL":0.015749,"SV":0.01452,"TR":0.008945999999999999,"ID":0.013646,"UK":0.01048,"KO":0.008'3,"NB":0.019434,"unsupported":0.5587179999999999}}}
{
  "items": [
    {
      "title": "nein",
      "arg": "nein"
    }
  ]
}

@AlexanderWillner
Copy link
Owner

  • Mh, this looks more or less how it should. It says: the translation is nein (well, it should be no but this is somehow related to DeepL that it does not recognize the input language based on a single word if not API key is given). The answer is a valid JSON that should be shown in Alfred. However, above you quoted the error Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700).
  • So you're writing dl nein and it does not return a valid result, right? To avoid confusion, try to translate a more complex input.
image

@gmdelisle
Copy link
Author

Yep, I have tried translating "Ich spiele gerne Musik."

Here is the output. I do see the translation in the output below, however is does not work with Alfred directly.
image

+ LANGUAGE=EN
+ LANGUAGE_SOURCE=auto
+ LANGUAGE_PREFERRED='["DE","EN"]'
+ KEY=
+ PRO=
+ POSTFIX=.
+ VERSION=2.0
+ PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin/
+++ dirname deepl.sh
++ cd .
++ pwd
+ DIR='/Users/macos/Library/CloudStorage/Dropbox/Préférences Alfred/Alfred.alfredpreferences/workflows/user.workflow.8E688CE1-8565-45D9-944F-7C43DF4CD1E2'
+ POSITIONAL=()
+ [[ 3 -gt 0 ]]
+ key=-l
+ case "$key" in
+ LANGUAGE=EN
+ shift
+ shift
+ [[ 1 -gt 0 ]]
+ key='Ich spiele gerne Musik.'
+ case "$key" in
+ POSITIONAL+=("$1")
+ shift
+ [[ 0 -gt 0 ]]
+ set -- 'Ich spiele gerne Musik.'
+ '[' -z 'Ich spiele gerne Musik.' ']'
+ query='Ich spiele gerne Musik.'
++ echo 'Ich spiele gerne Musik.'
++ sed 's/\"/\\\"/g'
+ query='Ich spiele gerne Musik.'
++ echo 'Ich spiele gerne Musik.'
++ sed 's/'\''/\\'\''/g'
+ query='Ich spiele gerne Musik.'
++ echo 'Ich spiele gerne Musik.'
++ iconv -f utf-8-mac -t utf-8
++ xargs
+ query='Ich spiele gerne Musik.'
+ [[ '' = '' ]]
+ [[ Ich spiele gerne Musik. != *\. ]]
++ echo 'Ich spiele gerne Musik.'
++ sed 's/\.$//'
+ query='Ich spiele gerne Musik'
+ data='{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"Ich spiele gerne Musik","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ HEADER=(--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')
+ '[' -n '' ']'
++ 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":{"jobs":[{"kind":"default","raw_en_sentence":"Ich spiele gerne Musik","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ result='{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"I like to play music","num_symbols":6},{"postprocessed_sentence":"I like playing music","num_symbols":5},{"postprocessed_sentence":"I enjoy playing music","num_symbols":5},{"postprocessed_sentence":"I love playing music","num_symbols":5}],"quality":"normal"}],"target_lang":"EN","source_lang":"DE","source_lang_is_confident":false,"detectedLanguages":{"EN":0.00035299999999999996,"DE":0.9164049999999999,"FR":0.000056999999999999999,"PT":0.000014999999999999999,"IT":0.00037999999999999997,"NL":0.0075899999999999999,"PL":0.002718,"CS":0.000129,"DA":0.021681,"ET":0.000147,"FI":0.000018999999999999999,"LT":0.000009999999999999999,"RO":0.00018999999999999998,"SK":0.00098,"SL":0.000024999999999999999,"SV":0.0011669999999999999,"TR":0.000165,"ID":0.000032999999999999999,"NB":'.005026,"unsupported":0.042893999999999998}}}
+ [[ {"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"I like to play music","num_symbols":6},{"postprocessed_sentence":"I like playing music","num_symbols":5},{"postprocessed_sentence":"I enjoy playing music","num_symbols":5},{"postprocessed_sentence":"I love playing music","num_symbols":5}],"quality":"normal"}],"target_lang":"EN","source_lang":"DE","source_lang_is_confident":false,"detectedLanguages":{"EN":0.00035299999999999996,"DE":0.9164049999999999,"FR":0.000056999999999999999,"PT":0.000014999999999999999,"IT":0.00037999999999999997,"NL":0.0075899999999999999,"PL":0.002718,"CS":0.000129,"DA":0.021681,"ET":0.000147,"FI":0.000018999999999999999,"LT":0.000009999999999999999,"RO":0.00018999999999999998,"SK":0.00098,"SL":0.000024999999999999999,"SV":0.0011669999999999999,"TR":0.000165,"ID":0.000032999999999999999,"NB":0.005 == *\"\e\r\r\o\r\"\:\{\"\c\o\d\e\"\:* ]]
+ osascript -l JavaScript -e 'function run(argv) {
      const translations = JSON.parse(argv[0])["result"]["translations"][0]["beams"].map(item => ({
        title: item["postprocessed_sentence"],
        arg: item["postprocessed_sentence"]
      }))

      return JSON.stringify({ items: translations }, null, 2)
    }' '{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"I like to play music","num_symbols":6},{"postprocessed_sentence":"I like playing music","num_symbols":5},{"postprocessed_sentence":"I enjoy playing music","num_symbols":5},{"postprocessed_sentence":"I love playing music","num_symbols":5}],"quality":"normal"}],"target_lang":"EN","source_lang":"DE","source_lang_is_confident":false,"detectedLanguages":{"EN":0.00035299999999999996,"DE":0.9164049999999999,"FR":0.000056999999999999999,"PT":0.000014999999999999999,"IT":0.00037999999999999997,"NL":0.0075899999999999999,"PL":0.002718,"CS":0.000129,"DA":0.021681,"ET":0.000147,"FI":0.000018999999999999999,"LT":0.000009999999999999999,"RO":0.00018999999999999998,"SK":0.00098,"SL":0.000024999999999999999,"SV":0.0011669999999999999,"TR":0.000165,"ID":0.000032999999999999999,"NB":0.'05026,"unsupported":0.042893999999999998}}}
{
  "items": [
    {
      "title": "I like to play music",
      "arg": "I like to play music"
    },
    {
      "title": "I like playing music",
      "arg": "I like playing music"
    },
    {
      "title": "I enjoy playing music",
      "arg": "I enjoy playing music"
    },
    {
      "title": "I love playing music",
      "arg": "I love playing music"
    }
  ]
}

@gmdelisle
Copy link
Author

Just wanted to add that I have 2 Macs.

  • MacBook Pro 16 M1
  • MacBook Air M2
    Same issue on both.

AlexanderWillner added a commit that referenced this issue Dec 14, 2023
@AlexanderWillner
Copy link
Owner

@gmdelisle
Copy link
Author

Sure thing, but I've tried it on my Mac I couldn't find deepl.sh.

I do see this file exists in your source code, but I just installed the workflow directly. How would I replace this bash script on my Mac?

@AlexanderWillner
Copy link
Owner

  • Go to Alfred settings > Workflows > Deepl-Translate > right click > Open in Finder
  • But I'll just push an update in parallel (only for getting debug information, not fixing it)

@gmdelisle
Copy link
Author

Yes it's spitting out a bit more info but not much as far as I can judge. Hope this helps!

[11:33:23.052] Logging Started...
[11:33:26.723] Deepl-Translate[Script Filter] Queuing argument 'Ich mag Klassik'
[11:33:28.318] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[11:33:28.324] STDERR: Deepl-Translate[Script Filter] execution error: Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700)
ERROR: Input ''

@AlexanderWillner
Copy link
Owner

Mh, getting closer, still not sure why it's not working for you. I created a version 2.0.2 with even more debugging information. Would you mind updating it or replace the deepl.sh file with https://raw.githubusercontent.com/AlexanderWillner/deepl-alfred-workflow2/master/deepl.sh ?

@gmdelisle
Copy link
Author

Hi!

Thanks for the update. There is a lot more information this time around.

This script shows my Deepl API key, so I've replaced it with below as to not paste it here in Github.

[01:22:47.400] Logging Started...
[01:22:51.421] Deepl-Translate[Script Filter] Queuing argument 'nein'
[01:22:52.204] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[01:22:52.210] STDERR: Deepl-Translate[Script Filter] curl -s -X POST 'https://api-free.deepl.com/v2/translate' -H 'Authorization: DeepL-Auth-Key <keyid>' -d 'text=nein' -d 'target_lang=en'

execution error: Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700)
ERROR w/ key: result '', query 'nein'

@AlexanderWillner
Copy link
Owner

  • Thanks, now I was able to reproduce it
  • The issue: the API key seems to be wrong
  • I'll enhance the script to communicate this to the user

@gmdelisle
Copy link
Author

Hey I can confirm this is fixed!
Indeed it does seem like the API key was the issue.
It seems like DeepL was making changes to their API's SLA in the past weeks. When I logged in today, my API key had disappeared from my account and I had to register for a new one with a new workflow.

New API key works now.

🙏 Many thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants