I am using scriptsmprovider module to trigger OTP to sms
I placed below script-to-script folder as mentioned in documentation The script takes the phone number as the only parameter. The message is expected at stdin… while triggering SMS i am getting below
script to trigger sms
import sys
import requests
import json
ACCESS_TOKEN = “xyz”
recipient_id = sys.argv[1]
message_text = sys.stdin.readline().rstrip()
url = f"https://text.com/messages?access_token={ACCESS_TOKEN}"
headers = {“Content-Type”: “application/json”}
message_payload = {
“recipient”: {“id”: recipient_id},
“message”: {“text”: message_text}
}
response = requests.post(url, headers=headers, data=json.dumps(message_payload))
if response.status_code == 200:
print(“Message sent successfully!”)
else:
print(“Failed to send message.”)
ERROR
[2023-05-15 19:55:34,467][516440][139749485766400][DEBUG][privacyidea.lib.config:185] Entering get_from_config with arguments (‘sms.identifier’,) and keywords {}
[2023-05-15 19:55:34,467][516440][139749485766400][DEBUG][privacyidea.lib.config:198] Exiting get_from_config with result sms
[2023-05-15 19:55:34,468][516440][139749485766400][DEBUG][privacyidea.lib.utils:1209] klass: <class ‘privacyidea.lib.smsprovider.ScriptSMSProvider.ScriptSMSProvider’>
[2023-05-15 19:55:34,468][516440][139749485766400][DEBUG][privacyidea.lib.tokens.smstoken:467] submitMessage: ‘636573’, to phone ‘15311262935’
[2023-05-15 19:55:34,469][516440][139749485766400][DEBUG][privacyidea.lib.smsprovider.ScriptSMSProvider:62] submitting message 636573 to 15311262935
[2023-05-15 19:55:34,472][516440][139749485766400][INFO][privacyidea.lib.smsprovider.ScriptSMSProvider:78] Starting script ‘/etc/privacyidea/scripts/send_message.py’.
[2023-05-15 19:55:34,476][516440][139749485766400][WARNING][privacyidea.lib.smsprovider.ScriptSMSProvider:84] Failed to execute script ‘/etc/privacyidea/scripts/send_message.py’: OSError(8, ‘Exec format error’)
[2023-05-15 19:55:34,477][516440][139749485766400][WARNING][privacyidea.lib.smsprovider.ScriptSMSProvider:86] Traceback (most recent call last):
File “/opt/privacyidea/lib/python3.8/site-packages/privacyidea/lib/smsprovider/ScriptSMSProvider.py”, line 79, in submit_message
p = subprocess.Popen(proc_args, cwd=self.script_directory, universal_newlines=True, stdin=subprocess.PIPE)
File “/usr/lib/python3.8/subprocess.py”, line 858, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “/usr/lib/python3.8/subprocess.py”, line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: ‘/etc/privacyidea/scripts/send_message.py’
[2023-05-15 19:55:34,477][516440][139749485766400][WARNING][privacyidea.lib.tokens.smstoken:358] The PIN was correct, but the SMS could not be sent! (SMSError(error_id=-1, description=‘Failed to start script for sending SMS.’))
[2023-05-15 19:55:34,478][516440][139749485766400][DEBUG][privacyidea.lib.tokens.smstoken:359] Traceback (most recent call last):
File “/opt/privacyidea/lib/python3.8/site-packages/privacyidea/lib/smsprovider/ScriptSMSProvider.py”, line 79, in submit_message
p = subprocess.Popen(proc_args, cwd=self.script_directory, universal_newlines=True, stdin=subprocess.PIPE)
File “/usr/lib/python3.8/subprocess.py”, line 858, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “/usr/lib/python3.8/subprocess.py”, line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: ‘/etc/privacyidea/scripts/send_message.py’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/opt/privacyidea/lib/python3.8/site-packages/privacyidea/lib/tokens/smstoken.py”, line 341, in create_challenge
success, sent_message = self._send_sms(
File “/opt/privacyidea/lib/python3.8/site-packages/privacyidea/lib/log.py”, line 194, in log_wrapper
f_result = func(*args, **kwds)
File “/opt/privacyidea/lib/python3.8/site-packages/privacyidea/lib/tokens/smstoken.py”, line 468, in _send_sms
ret = sms.submit_message(phone, message)
File “/opt/privacyidea/lib/python3.8/site-packages/privacyidea/lib/smsprovider/ScriptSMSProvider.py”, line 88, in submit_message
raise SMSError(-1, “Failed to start script for sending SMS.”)
privacyidea.lib.smsprovider.SMSProvider.SMSError: Failed to start script for sending SMS.
[2023-05-15 19:55:34,479][516440][139749485766400][DEBUG][privacyidea.lib.tokens.smstoken:198] Exiting create_challenge with result (False, ‘The PIN was correct, but the SMS could not be sent!’, None, {‘attributes’: {‘state’: None, ‘valid_until’: ‘2023-05-15 20:00:34.479172’}})
Can you please correct me incase if am doing anything wrong in script