Я получаю закодированную строку из jasmis-sms, исходная строка áéíóú ñaña!
, jasmin выполняет некоторую кодировку и дает мне:
����� �a�a!
(в моем терминале)
который chardet обнаруживает как charset: windows-1252
Но при попытке расшифровать его с помощью
Message.decode('windows-1252')
Но это возвращает
<type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\xe1' in position 11: ordinal not in range(128)
Строкаприходит от jasmin-sms на скрипте перехвата Python
Сценарий запускается jasmin-sms при получении SMS через smpp, он вводит глобальную переменную routable
, которая содержит все данные SMS, полный кодэто:
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'] )
И я не уверен, как решить эту проблему.
И помощь очень ценится!