Python Forum

Full Version: sms messaging
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import messaging
from messaging import sms
from messaging.sms import gsm0338
from messaging.sms import SmsSubmit


file = open('/var/spool/asterisk/sms_temp/gsm_sms_out/m_body.txt')                        
m_body = file.read()
file.close()

file = open('/var/spool/asterisk/sms_temp/gsm_sms_out/m_to.txt')                        
m_to = file.read()
file.close()






sms = SmsSubmit(m_to, m_body.decode('UTF-8'))

for pdu in sms.to_pdu():
       pdu_out = str(pdu.pdu) 
       send_pdu_cmd="asterisk -rx " + "'dongle pdu COSMOTE " + pdu_out + "'"
       os.system(send_pdu_cmd)


                

exit()
The above code is for sending sms messages with Asterisk and chan_dongle. It works well in general, but i found that if the message includes smiles it ends with : "ValueError: chr() arg not in range(256)"!

For example if the m_body.txt is "Δοκιμή!" the script runs without error.

If the m_body.txt is "Δοκιμή!Smile" it gives :


":~# /var/lib/asterisk/agi-bin/PDU_out.py
Traceback (most recent call last):
File "/var/lib/asterisk/agi-bin/PDU_out.py", line 25, in <module>
for pdu in sms.to_pdu():
File "/usr/lib/python2.7/dist-packages/messaging/sms/submit.py", line 83, in to_pdu
sms_msg_pdu = self._get_msg_pdu()
File "/usr/lib/python2.7/dist-packages/messaging/sms/submit.py", line 258, in _get_msg_pdu
message_pdu = [pack_8bits_to_ucs2(self.text)]
File "/usr/lib/python2.7/dist-packages/messaging/utils.py", line 166, in pack_8bits_to_ucs2
nmesg += chr(ord(n) >> 8) + chr(ord(n) & 0xFF)
ValueError: chr() arg not in range(256)"

How can i solve this?
Thank u!
Are you using python 2, right?
Try to run it with python 3, chr() in python 3 can handle much more characters.

>>> ord('☺')
9786
>>> chr(9786)
'☺'