How to check the work of a python script?

I wrote a python script to send sms through a hardware sms gateway.
This script works if I just pass a parameter on the command line.

python3 +9999999999 'pass 123456'

Script does all the necessary manipulations and sends SMS.
If I refer to it from the PI it doesn’t work and throws an error. I have enabled logging, but it does not show what is happening with the script.
How can I find out why the script is not being executed through the PI?

I tried to catch stdin like this:

input_number = sys.argv[1]
temptext = sys.stdin.readline().rstrip()
#temptext = sys.argv[2]

I tried to run the script as root, as a privacyidea, and set permissions to 777 for everything.
The script works from under su - privacyidea

[2023-08-14 12:52:50,838][190294][140237361915456][DEBUG][privacyidea.lib.resolver:194] Exiting get_resolver_object with result <privacyidea.lib.resolvers.LDAPIdResolver.IdResolver object >
[2023-08-14 12:52:50,838][190294][140237361915456][DEBUG][privacyidea.lib.resolvers.LDAPIdResolver:275] Reading '59ca571e-79c9-4672-9d43-5d22c76fc52b' from cache for 'getUserInfo'
[2023-08-14 12:52:50,841][190294][140237361915456][DEBUG][privacyidea.lib.utils:1209] klass: <class 'privacyidea.lib.smsprovider.ScriptSMSProvider.ScriptSMSProvider'>
[2023-08-14 12:52:50,841][190294][140237361915456][DEBUG][privacyidea.lib.tokens.smstoken:468] submitMessage: 'pass 991604', to phone '+9999999999'
[2023-08-14 12:52:50,841][190294][140237361915456][DEBUG][privacyidea.lib.smsprovider.ScriptSMSProvider:68] submitting message pass 991604 to +99999999999
[2023-08-14 12:52:50,844][190294][140237361915456][INFO][privacyidea.lib.smsprovider.ScriptSMSProvider:79] Starting script '/etc/privacyidea/scripts/'.
[2023-08-14 12:52:51,094][190294][140237361915456][WARNING][privacyidea.lib.smsprovider.ScriptSMSProvider:94] Script '/etc/privacyidea/scripts/' failed to execute with error c>
[2023-08-14 12:52:51,094][190294][140237361915456][WARNING][privacyidea.lib.tokens.smstoken:358] The PIN was correct, but the SMS could not be sent! (SMSError(error_id=-1, description='Err>
[2023-08-14 12:52:51,095][190294][140237361915456][DEBUG][privacyidea.lib.tokens.smstoken:359] Traceback (most recent call last):
  File "/opt/privacyidea/lib/python3.10/site-packages/privacyidea/lib/tokens/", line 341, in create_challenge
    success, sent_message = self._send_sms(
  File "/opt/privacyidea/lib/python3.10/site-packages/privacyidea/lib/", line 190, in log_wrapper
    f_result = func(*args, **kwds)
  File "/opt/privacyidea/lib/python3.10/site-packages/privacyidea/lib/tokens/", line 469, in _send_sms
    ret = sms.submit_message(phone, message)
  File "/opt/privacyidea/lib/python3.10/site-packages/privacyidea/lib/smsprovider/", line 96, in submit_message
    raise SMSError(-1, "Error during execution of the script.")
privacyidea.lib.smsprovider.SMSProvider.SMSError: Error during execution of the script.

[2023-08-14 12:52:51,095][190294][140237361915456][DEBUG][privacyidea.lib.tokens.smstoken:194] Exiting create_challenge with result (False, 'The PIN was correct, but the SMS could not be s>
[2023-08-14 12:52:51,095][190294][140237361915456][DEBUG][privacyidea.lib.token:194] Exiting check_token_list with result (False, {'multi_challenge': [], 'message': 'The PIN was correct, b>
[2023-08-14 12:52:51,096][190294][140237361915456][DEBUG][privacyidea.lib.token:194] Exiting check_user_pass with result (False, {'multi_challenge': [], 'message': 'The PIN was correct, bu>

Look, at the command line run your “script” with the python interpreter.
Not so in privacyIDEA.

An experienced admin might issue the educated guess, that your “script” is not executable or does miss the interpreter within.

No, it was executable, and contained everything that was needed.
It worked fine from the command line, from the interpreter, and everything but the PI. I checked it before posting here.
The problem turned out to be banal - the encodings did not match.

Thank you.
The only issue is this is a big and heavy script and it takes longer to execute and the UI doesn’t wait for a response and the connection timeouts.

privacyIDEA request failed: 500 read timeout

Tell me where this parameter changes, I could not find it in the documentation. Thank you