0

我从 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)

字符串来自拦截 python 脚本上的 jasmin-sms

该脚本由 jasmin-sms 在通过 smpp 接收短信时启动,它注入一个全局变量routable,其中包含所有短信数据,完整代码为:

蟒蛇2

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'] )

而且我不确定如何解决这个问题。

非常感谢您的帮助!

4

0 回答 0