Skip to content
\n

I have following code to send sms

\n
def send_alert_helper(data: dict ):\n    '''\n        param: dict(ip, port, alert_username, alert_password, , alert_id, mobile_number, message)\n    '''\n    try:\n        parts, encoding_flag, msg_type_flag = make_parts(u\"{}\".format(data.get('message')))\n        client = smpplib.client.Client(data.get('ip'), int(data.get('port')))\n        client.set_message_sent_handler(\n            lambda pdu: sys.stdout.write('send {} {} \\n'.format(pdu.sequence, pdu.message_id))\n        )\n        client.connect()\n        client.bind_transceiver(system_id = data.get('alert_username'), password = data.get('alert_password'))\n\n        for part in parts:\n            pdu = client.send_message(\n                source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,\n                source_addr_npi=smpplib.consts.SMPP_NPI_UNK,\n                source_addr= data.get('alert_id'),\n        \n                dest_addr_ton=smpplib.consts.SMPP_TON_INTL,\n                destination_addr = data.get('mobile_number'),\n                short_message=part,\n                data_coding=encoding_flag,\n                esm_class=msg_type_flag,\n                registered_delivery=False,       \n            )\n            client.disconnect()\n        \n    except ConnectionError:\n        raise ConnectionError()\n\n    except Exception as e:\n        raise Exception()\n
\n

do you have any idea about that?
\nBut, when I use phone number i can send long length sms also. We have following code for that

\n
def send_sms_helper(data: dict):\n    '''\n        param: data-> dict (ip, port, system_id, system_password, sender_id, mobile_number, message)\n    '''\n    try:\n        parts, encoding_flag, msg_type_flag = make_parts(u\"{}\".format(data.get('message')))\n        client = smpplib.client.Client(data.get('ip'), data.get('port'))\n        client.set_message_sent_handler(\n            lambda pdu: sys.stdout.write('send {} {} \\n'.format(pdu.sequence, pdu.message_id))\n        )\n        client.connect()\n        client.bind_transmitter(system_id = data.get('system_id'), password = data.get('system_password'))\n        for part in parts:\n            pdu = client.send_message(\n                source_addr_ton=smpplib.consts.SMPP_TON_INTL,\n                source_addr=data.get('sender_id'),\n                        \n                dest_addr_ton=smpplib.consts.SMPP_TON_INTL,\n                destination_addr = data.get('mobile_number'),\n                short_message=part,\n                data_coding=encoding_flag,\n                esm_class=msg_type_flag,\n                registered_delivery=True,\n        )\n        client.disconnect()\n\n    except ConnectionError: \n        raise ConnectionError()\n       \n    except Exception as e:\n        raise Exception()\n\n
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

my bad, this issuse occured due to immediate disconnect inside for loop.

","upvoteCount":1,"url":"https://github.com/python-smpplib/python-smpplib/discussions/209#discussioncomment-3411708"}}}
Discussion options

You must be logged in to vote

my bad, this issuse occured due to immediate disconnect inside for loop.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lujamaharjan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant