I'm receiving an encoded string from jasmis-sms, the original string is áéíóú ñaña!
, jasmin does some encoding and gives me:
����� �a�a!
(in my terminal)
which chardet detects as charset: windows-1252
But when trying to decode that with
Message.decode('windows-1252')
But that returns
<type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\xe1' in position 11: ordinal not in range(128)
String is coming from jasmin-sms on an interception python script
The script is launched by jasmin-sms on receiving an SMS via smpp, it injects a global variable routable
, which contains all the SMS's data, the complete code is:
python2
import urllib
import urllib2
import re
import chardet
file=open('/opt/jasmin-scritps/interception/mo-interceptor.log','a')
file.write('===============================================================================\n')
file.write('Start logging...\n')
SMS_to = routable.pdu.params['destination_addr']
SMS_from = routable.pdu.params['source_addr']
SMS_message = routable.pdu.params['short_message']
file.write('To: [%s]\n' % SMS_to )
file.write('From: [%s]\n' % SMS_from )
file.write('ShortMessage: [%s]\n' % SMS_message.encode("hex") )
file.write('data-coding: [%s]\n' % routable.pdu.params['data_coding'] )
file.write('charset: %s\n' % chardet.detect( SMS_message )['encoding'] )
file.write('decoded: [%s]\n' % SMS_message )
file.write('SmppSatus: [%s]\n' % smpp_status )
file.write('Content: [%s]\n' % routable.pdu.params['short_message'] )
And I'm not sure how to solve this problem.
And help is really appreciated!