在smpplib Python上接收SMS时出现问题

2024-07-06 23:55:54 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用命令时,接收带有拉丁字符的短信时出现问题pdu.short\信息.decode('utf-8')在修剪拉丁字符之前对所有内容进行解码。有人知道怎么解决这个问题吗?你知道吗

硬件是启用了smpp服务器的goip4 我尝试用python3.6和3.7解决同样的问题

代码来自互联网,但我在我的项目中使用相同的代码。你知道吗

logging.basicConfig(level='DEBUG')
client = smpplib.client.Client('123.456.789.101', 1123)
def getPdu(pdu):
    print(pdu.short_message.decode('utf-8'))
client.set_message_received_handler(getPdu)
client.connect()
client.bind_transceiver(system_id='1234', password='5678')
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts('Руский из питона 3, кодировочку зажги!\n')
for part in parts:
    pdu = client.send_message(
        source_addr_ton=smpplib.consts.SMPP_TON_NWSPEC,
        source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        source_addr='1591',
        dest_addr_ton=smpplib.consts.SMPP_TON_NATNL,
        dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure thease two params are byte strings, not unicode:
        destination_addr='79531498486',
        short_message=part,
        data_coding=encoding_flag,
        esm_class=msg_type_flag,
        registered_delivery=True,
    )
    print(pdu.sequence)
client.listen()

Tags: 代码clientsourcemessagesmpp字符utfflag