【问题标题】:Encoding a unicode prints the string correctly,but using a API for sending SMS ,sends the SMS with question marks编码 unicode 可以正确打印字符串,但使用 API 发送 SMS 会发送带有问号的 SMS
【发布时间】:2015-07-09 09:34:49
【问题描述】:

我想用多种语言发送短信。它适用于英语。但如果我想用法语或西班牙语发送短信,我就有问题了。 消息是 Unicode 格式的。在此之后

message = message.encode('utf-8')

消息是一个字符串并正确打印结果。但是,当我想使用 API 发送消息时,它会发送问号(????????)而不是 à、έ等字符.我已经在我的手机上测试过了。 当我做消息[0]时,它给了我“?”。所以我猜编码('utf-8')不能正常工作。消息包含法语或西班牙语或德语或任何字符。它是一个变量,所以每次都包含不同的语言。 这是我的代码示例:

to = queue_mobile 
message = queue_message
gateway = AfricasTalkingGateway(username, apikey)

try:
    results = gateway.sendMessage(to, message)
    for recipient in results:
        print 'number=%s;status=%s;messageId=%s;cost=%s' % (recipient['number'],
                                                                        recipient['status'],
                                                                        recipient['messageId'],
                                                                        recipient['cost'])

如果不对消息进行编码,它会从 API 返回异常(ascii 编解码器无法对字符 0-6 进行编码)。 如果我对消息进行编码('utf-8'),它会发送短信但带有问号。

【问题讨论】:

    标签: python-2.7 unicode encode


    【解决方案1】:

    你使用哪个 api? 你能展示一些示例代码吗? 你们的短信网关支持哪些字符集?

    在 GSM 中,每种语言都有不同的 7 位字符集。

    也许这会有所帮助: https://en.wikipedia.org/wiki/GSM_03.38#GSM_7_bit_default_alphabet_and_extension_table_of_3GPP_TS_23.038_.2F_GSM_03.38

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多