首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python smpplib截断smpp凭据

Python smpplib截断smpp凭据
EN

Stack Overflow用户
提问于 2019-02-22 08:42:47
回答 1查看 604关注 0票数 0

我正在使用Python SMPP lib发送SMS。当我尝试使用更长的凭据连接到SmppServer时,用户名和密码被截断,授权失败。

身份验证失败案例:-用户名/密码长度超过16个字符

传递大小写:-用户名/密码不超过16个字符

因此,由于上面的观察,我确信SMMPP网关没有问题。我试图自己通信的网关可以接受任何长度的用户名/密码。

下面是我的代码,它将smpplib封装到一个自定义类中:

代码语言:javascript
复制
import smpplib
import smpplib.gsm

from smpplib.client import Client


class SmppClientConfig(object, ):

    def __init__(self, host, port, username, password, source, target, on_delivered_cb, on_sent_cb):
        self.HOST = host
        self.PORT = port
        self.USERNAME = username
        self.PASSWORD = password
        self.SOURCE = source
        self.TARGET = target
        self.ON_RECEIVED_CALLBACK = on_sent_cb
        self.ON_DELIVERED_CALLBACK = on_delivered_cb


class SmppSenderClient(object):

    def __init__(self, config: SmppClientConfig):
        print('Creating SMPP client config with host: ' + config.HOST + ' port: ' + str(config.PORT))

        self._config = config
        self._client = Client(config.HOST, config.PORT)
        self._on_delivered_callback = config.ON_DELIVERED_CALLBACK
        self._on_received_callback = config.ON_RECEIVED_CALLBACK

        self._init_client()

    def _init_client(self):
        print('Initializing SmppSender client with username: ' + self._config.USERNAME)

        self._register_events()
        self._client.connect()
        self._client.bind_transmitter(system_id=self._config.USERNAME, password=self._config.PASSWORD)

    def _register_events(self):
        print('Registering Smpp events')
        self._client.set_message_sent_handler(self._config.ON_DELIVERED_CALLBACK)
        self._client.set_message_received_handler(self._config.ON_RECEIVED_CALLBACK)

    def send_message(self, message: str):
        print('Sending SMS message to target: ' + self._config.TARGET)
        parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message)

        for part in parts:
            self._client.send_message(
                source_addr_ton=smpplib.consts.SMPP_TON_INTL,
                source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                source_addr=self._config.SOURCE,

                dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
                dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                destination_addr=self._config.TARGET,
                short_message=part,

                data_coding=encoding_flag,
                esm_class=msg_type_flag,
                registered_delivery=True,
            )

我不确定这是库的预期行为还是限制。我已经尝试了查找这个库的文档,但是除了this之外,我找不到任何其他的东西。

如果您遇到类似的问题,请告知任何可能的解决方法,或者这是否是SMPP协议中的预期行为(这是非常不可能的)。

更新:我在源代码中发现了这个限制:

代码语言:javascript
复制
class BindTransmitter(Command):
    """Bind as a transmitter command"""

    params = {
        'system_id': Param(type=str, max=16),
        'password': Param(type=str, max=9),
        'system_type': Param(type=str, max=13),
        'interface_version': Param(type=int, size=1),
        'addr_ton': Param(type=int, size=1),
        'addr_npi': Param(type=int, size=1),
        'address_range': Param(type=str, max=41),
    }

    # Order is important, but params dictionary is unordered
    params_order = (
        'system_id', 'password', 'system_type',
        'interface_version', 'addr_ton', 'addr_npi', 'address_range',
    )

    def __init__(self, command, **kwargs):
        super(BindTransmitter, self).__init__(command, need_sequence=False, **kwargs)

        self._set_vars(**(dict.fromkeys(self.params)))
        self.interface_version = consts.SMPP_VERSION_34

正如您所看到的,BindTransmitter构造器(__init__)将system_id截断为最大长度16,将passsword截断为9。

EN

回答 1

Stack Overflow用户

发布于 2019-02-22 10:03:02

我查了官方的SMPP协议规范。根据规范,对于连接类型:transmittersystem_id应该是最大值16,password应该是9。

以下是此规格的截图:

如果有人感兴趣,这是规范的link

因此,总之,规范的库实现是正确的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54818392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档