Giter Club home page Giter Club logo

python-smpplib's People

Contributors

a-solovev avatar asdfuser avatar baverman avatar code-of-kpp avatar davidshepherd7 avatar djkim1987 avatar eigenein avatar emnoor avatar fpalamour avatar jakob-o avatar kammala avatar kefiriaus avatar lynesth avatar orn1983 avatar pespin avatar stefanruijsenaars avatar whyteks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-smpplib's Issues

Sending big russian text makes message improperly encoded

Hello.

I have service which sends SMS messages and will accept parameters via SMPP

I'm using this lines of code to send message:

    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text)

    client = smpplib.client.Client(sms_host, sms_port)

    client.set_message_sent_handler(
        lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
    client.set_message_received_handler(
        lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))

    client.connect()
    client.bind_transceiver(system_id=system_id, password=password)

    for part in parts:
        pdu = client.send_message(
            source_addr_ton=5,
            source_addr_npi=0,
            # Make sure it is a byte string, not unicode:
            source_addr=source_addr,

            dest_addr_ton=1,
            dest_addr_npi=1,
            # Make sure thease two params are byte strings, not unicode:
            destination_addr=dest_addr,
            short_message=part,

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

When I try to send russian or any cyrrillic text, SMS service sends me that kind of text:

Привеееет привввввееееееееет прип�䀄㠄㼄䀄㠄㈄㈄㈄㈄㈄㈄㈄㔄㔄㔄㔄㔄㔄䈄䈄䈄䈄䈄䰄䰄䰄䰀 䴄䈄㸀 㐄�лгий дооолги и оченнь доооолги  т�㔄㔄㔄㨄䄄䈀 㐄㬄伀 㼄䀄㸄㈄㔄䀄㨄㠀 㼄䀄㸄㈄㔄䀄㨄  䄄㠄䄄䈄�мы система вклбченр вы йцк   нужн�  㨄㬄〄㈄  㤄䘄䌄㨄㔄�

The interesting thing is that some parts are correct and some parts become weird chineese symbols.

Why this is happening?

Is there need to add type checks for parameters? Maybe in debug-mode.

Sorry for my English.

I noticed, there are UnicodeError-exceptions after passing unicode-string to SubmitSM-functions sometimes (at least, the destination number). It was accidentally done by database engine (sqlalchemy).
Now I'm converting the phone number to string-type by hand before SubmitSM-calls.

Broken PDU

INFO:smpplib.client:Connecting to 192.168.0.15:8023...
bind_transceiver
DEBUG:smpplib.client:Receiver mode
DEBUG:smpplib.client:Sending bind_transceiver PDU
DEBUG:smpplib.client:>>0000001f000000090000000000000001766f69700031323334000034000000 (31 bytes)
DEBUG:smpplib.client:Waiting for PDU...
WARNING:smpplib.client:Receive broken pdu... '\r\n'
Traceback (most recent call last):
  File "sample.py", line 23, in <module>
    client.bind_transceiver(system_id='voip', password='1234')
  File "/home/smsserver/smpplib/client.py", line 151, in bind_transceiver
    return self._bind('bind_transceiver', **kwargs)
  File "/home/smsserver/smpplib/client.py", line 132, in _bind
    resp = self.read_pdu()
  File "/home/smsserver/smpplib/client.py", line 212, in read_pdu
    raise exceptions.PDUError('Broken PDU')
smpplib.exceptions.PDUError: Broken PDU
WARNING:smpplib.client:Command unbind failed: Incorrect BIND Status for given command. Ignored
INFO:smpplib.client:Disconnecting...

enquire link interval

Hi,

I've been trying to connect to a server who needs certain enquire link interval, is this configurable on the library? (or I need to do a wrapper)

DEBUG Mode

I need your help with following issues.

  1. First how can I disable/enable DEBUG output to stdout and how to redirect to a log?
  2. For responses received from ESME e.g. against sm_submit, an PDU is received but can not read message on stdout. Please find below output

DEBUG: Sending submit_sm PDU########################################################################################################## |
DEBUG: >> 000000ad00000004000000000000000b0005005054434c0000013932353134383330303333000000000000010000007d44656172205369722f4d6164616d2c2053616c61727920666f7220746865206d6f6e7468206f662053657074656d626572203230313520686173206265656e20637265646974656420746f20796f75722072657370656374697665206163636f756e742e20526567617264732c204852204f7065726174696f6e732020 173 bytes
DEBUG: Waiting for PDU...
DEBUG: << 0000001980000004000000000000000b363036453930363000 25 bytes
DEBUG: Read submit_sm_resp PDU

submit_sm_resp PDU: How do I read it ?

Thanks

Getting KeyError: 9

Hi am having some issues here is a traceback. This is happening when binding as a receiver only. Transmitter is working Okay

Traceback (most recent call last):
  File "testt.py", line 17, in <module>
    client.bind_receiver(system_id='****', password='****')
  File "/usr/local/lib/python2.7/dist-packages/python_smpplib-1.0.1-py2.7.egg/smpplib/client.py", line 146, in bind_receiver
    return self._bind('bind_receiver', **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/python_smpplib-1.0.1-py2.7.egg/smpplib/client.py", line 137, in _bind
    consts.DESCRIPTIONS[resp.status]), int(resp.status))
KeyError: 9
WARNING:smpplib.client:Command unbind failed: Incorrect BIND Status for given command. Ignored
INFO:smpplib.client:Disconnecting...

Setting message_id

Please is it possible to set The unique message identifier, that will later be returned in the DLR for reference purpose.

Let me explain my current process below:

**_Our approach is we send a message to the smsc gateway we get an id from smsc, we save this id and when DLR comes we match the id from the dlr to the id we previously save (because we push million of messages for a short period this approach isn't optimal for us, the back and forth to the database).

what I will like to acheive is if there is a way we can add a parameter to the submit message to smsc that and retrieve this id when the dlr comes back._**

Bind trouble

Hi,
I am trying to use this library but I am getting bind error:

client created
INFO:smpplib.client:Connecting to smpp0.nexmo.com:8000...
connected
DEBUG:smpplib.client:Sending bind_transmitter PDU
DEBUG:smpplib.client:>>0000002b000000020000000000000001623433366139373500354c674f7538644a00736d70700034000000 (43 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<00000011800000020000000d0000000100 (17 bytes)
DEBUG:smpplib.client:Read bind_transmitter_resp PDU
Traceback (most recent call last):
  File "test_smpp.py", line 24, in 
    client.bind_transmitter(system_id='*****', password='***************', system_type='smpp')
  File "build/bdist.linux-x86_64/egg/smpplib/client.py", line 143, in bind_transmitter
  File "build/bdist.linux-x86_64/egg/smpplib/client.py", line 138, in _bind
smpplib.exceptions.PDUError: ('(13) bind_transmitter_resp: Bind Failed', 13)
WARNING:smpplib.client:Command unbind failed: Incorrect BIND Status for given command. Ignored
INFO:smpplib.client:Disconnecting...

Code I used is:

import logging
import sys

import smpplib.gsm
import smpplib.client
import smpplib.consts


# if you want to know what's happening
logging.basicConfig(level='DEBUG')

client = smpplib.client.Client('smpp0.nexmo.com', 8000)
print('client created')

# Print when obtain message_id
client.set_message_sent_handler(
    lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
client.set_message_received_handler(
    lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))

client.connect()
print('connected')

client.bind_transmitter(system_id='***', password='*********', system_type='smpp')
print('bind finished')

client.unbind()
print('unbind')

client.disconnect()
print('disconnected')

print('ENDE')

Can you please tell me am I missing something?

Thank you kindly

Unkwown status

Please help review this error

Traceback (most recent call last):
File "C:\Python27\smpplib\another.py", line 42, in
client.listen()
File "C:\Python27\smpplib\smpplib\client.py", line 285, in listen
consts.DESCRIPTIONS.get(p.status, 'Unknown status')), int(p.status))
smpplib.exceptions.PDUError: ('(11) submit_sm_resp: Invalid Destination Address', 11)
DEBUG:smpplib.client:Sending unbind PDU
DEBUG:smpplib.client:>>00000010000000060000000000000002 (16 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<00000010800000060000000000000002 (16 bytes)
DEBUG:smpplib.client:Read unbind_resp PDU
INFO:smpplib.client:Disconnecting...

Sequence ID in enqure_links

Hi.

DEBUG:smpplib.client:Read enquire_link_resp PDU
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001000000015000000001625d269' (16 bytes)
DEBUG:smpplib.client:Read enquire_link PDU
DEBUG:smpplib.client:Sending enquire_link_resp PDU
DEBUG:smpplib.client:>>b'00000010800000150000000000000001' (16 bytes)
DEBUG:smpplib.client:Link Enquiry...
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:Socket timeout, listening again

After that smsc closes connection.
How to fix problem?

error: [Errno 9] Bad file descriptor

When I try to bind as transceiver on a thread, I get this error:

DEBUG: Connecting to *******_:__...
DEBUG: I am receiver
DEBUG: Sending bind_transceiver PDU
DEBUG: >> 0000002500000009000000000000000172616d6f6e32004e56586b73395041000034000000 37 bytes
DEBUG: Waiting for PDU...
DEBUG: << 00000016800000090000000000000001000210000134 22 bytes
DEBUG: Read bind_transceiver_resp PDU
DEBUG: Sending unbind PDU
DEBUG: >> 00000010000000060000000000000003 16 bytes
DEBUG: Waiting for PDU...
DEBUG: Waiting for PDU...
DEBUG: << 00000010800000060000000000000003 16 bytes
DEBUG: Read unbind_resp PDU
DEBUG: Disconnecting...
DEBUG: Socket timeout, listening again
DEBUG: Waiting for PDU...
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(_self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/smpplib/client.py", line 303, in listen
p = self.read_pdu()
File "/usr/local/lib/python2.7/dist-packages/smpplib/client.py", line 233, in read_pdu
raw_len = self._socket.recv(4)
File "/usr/lib/python2.7/socket.py", line 170, in _dummy
raise error(EBADF, 'Bad file descriptor')
error: [Errno 9] Bad file descriptor

If not doing it within a thread, the program keeps connecting and disconnecting waiting for a PDU, so it seems to be fine, but as soon as I call the client.listen() function the execution stops there, so I supose that, in order to be able to send SMS, I need to start it on a thread.

But, when starting it on a thread, I am able to send a message after the bind command, which is sent just before the crash.

unable to add compare_invoke.py file to setup.py

Hi,

We downloaded the code trying to add custom .py files to the setup.py.

The following is the snapshot,

from setuptools import setup, find_packages
import sys

extra = {}
if sys.version_info >= (3,):
extra['use_2to3'] = True

setup(name="project",
  version='1.0.1',
  description='SMPP library for python',
  packages=['project'],
  zip_safe=True,
  package_data={'': ['project/face.dat','project/testing.dat','project/compare_invoke.py']},
  classifiers=[
    'Development Status :: 4 - Beta',
    'Operating System :: OS Independent',
    'Programming Language :: Python',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 2.7',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.1',
    'Programming Language :: Python :: 3.2',
    'Topic :: Communications :: Telephony',
    'Intended Audience :: Telecommunications Industry',
    'License :: OSI Approved',
    ],
  **extra
)

Once i ran the command python setup.py install they are no errors but i am unable to import from python command prompt.

I tried from python command line as from compare_invoke import checkme
error was

ImportError: No module named compare_invoke

Pls suggest

Thanks
vijay

Constant value not correct

In the file consts.py there is a constant at line 206
SMPP_UDHIEIE_PORT16 = 0x04

the correct value is 0x05, can someone please fix it?

Thank you.

Connection refused

I am getting this error....could you assist

Traceback (most recent call last):
  File "python-smpplib/test1.py", line 4, in <module>
    import smpplib.gsm
  File "/root/python-smpplib/smpplib/__init__.py", line 26, in <module>
    from . import client
  File "/root/python-smpplib/smpplib/client.py", line 83
    except (exceptions.PDUError, exceptions.ConnectionError), e:
                                                            ^

Sending message didn't work after using beautifulsoup to remove nbsp and amp

I can't send message after converting the html message to text message. But it's working if im not using beautifulsoup

I'm new to python and it took me 1 week to finally to understand un library and make it work. Please i need help. Thanks

from bs4 import BeautifulSoup
html = "Thank you for registering to SM&nbsp;PAY BILLS, LOAD TO WIN promo. Keep buying &amp; loading any SMART, TNT, &amp; SUN participating products only in SM, Savemore, Hypermarket, Waltermart, &amp; Alfamart for more chances to win a P10,000 SM Shopping spree. Promo runs Aug1-Sep30 2019. DTI # xxxx. For more info visit xxxxx. Access to this site is FREE.&nbsp; This msg is FREE."
soup = BeautifulSoup(html, features="html5lib")
msg = soup.get_text()
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(msg)
client = smpplib.client.Client('x.x.x.x', 'xxxx')

# Print when obtain message_id
client.set_message_sent_handler(
    lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
client.set_message_received_handler(
    lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))

client.connect()
client.bind_transmitter(system_type="XXXX", system_id='XXXX', password='XXXX')

for part in parts:
    pdu = client.send_message(
        source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,
        source_addr_npi=smpplib.consts.SMPP_NPI_IP,
        # Make sure it is a byte string, not unicode:
        source_addr='SmartPromos',

        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
        #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure thease two params are byte strings, not unicode:
        destination_addr=mobile,
        short_message=part,

        data_coding=encoding_flag,
        #data_coding=smpplib.consts.SMPP_ENCODING_ISO10646,
        esm_class=msg_type_flag,
        #esm_class=0x40,
        registered_delivery=True,
        #registered_delivery=smpplib.consts.SMPP_SMSC_DELIVERY_RECEIPT_BOTH
    )
    client.read_pdu()
    print(pdu.sequence)
#client.listen()
client.disconnect()

Here's what I got when i send the message without using beautifulsoup

INFO:smpplib.client:Connecting to x.x.x.x:xxxx...
DEBUG:smpplib.client:Sending bind_transmitter PDU
DEBUG:smpplib.client:>>b'0000002e0000000200000000000000014d5253493737363300404d72533737363300524557415244530034000000' (46 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001e8000000200000000000000015465787450617373000210000134' (30 bytes)
DEBUG:smpplib.client:Read bind_transmitter_resp PDU
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000d700000004000000000000000200050e536d61727450726f6d6f73000100363339313735343333363033004000000000010000009f0500036303015468616e6b20796f7520666f72207265676973746572696e6720746f20534d266e6273703b5041592042494c4c532c204c4f414420544f2057494e2070726f6d6f2e204b65657020627579696e672026616d703b206c6f6164696e6720616e7920534d4152542c20544e542c2026616d703b2053554e2070617274696369706174696e672070726f6475637473206f6e6c7920696e20534d2c' (215 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000023030303030303845333500' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
2
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000d700000004000000000000000300050e536d61727450726f6d6f73000100363339313735343333363033004000000000010000009f05000363030220536176656d6f72652c2048797065726d61726b65742c2057616c7465726d6172742c2026616d703b20416c66616d61727420666f72206d6f7265206368616e63657320746f2077696e2061205031302c30303020534d2053686f7070696e672073707265652e2050726f6d6f2072756e7320417567312d536570333020323031392e20445449202320787878782e20466f72206d6f726520' (215 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000033030303030303845333600' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
3
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'0000008400000004000000000000000400050e536d61727450726f6d6f73000100363339313735343333363033004000000000010000004c050003630303696e666f2076697369742078787878782e2041636365737320746f2074686973207369746520697320465245452e266e6273703b2054686973206d736720697320465245452e' (132 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000043030303030303845333700' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
4
INFO:smpplib.client:Disconnecting...
WARNING:smpplib.client:<smpplib.client.Client object at 0x7fc939aa9438> is disconnecting in the bound state

and this one is when the message was converted to text using beautiful soup

INFO:smpplib.client:Connecting to x.x.x.x:xxxx...
DEBUG:smpplib.client:Sending bind_transmitter PDU
DEBUG:smpplib.client:>>b'0000002e0000000200000000000000014d5253493737363300404d72533737363300524557415244530034000000' (46 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001e8000000200000000000000015465787450617373000210000134' (30 bytes)
DEBUG:smpplib.client:Read bind_transmitter_resp PDU
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000c400000004000000000000000200050e536d61727450726f6d6f73000100363339313735343333363033004000000000010008008c050003160601005400680061006e006b00200079006f007500200066006f00720020007200650067006900730074006500720069006e006700200074006f00200053004d00a0005000410059002000420049004c004c0053002c0020004c004f0041004400200054004f002000570049004e002000700072006f006d006f002e0020004b0065006500700020' (196 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000023030303030303845334200' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
2
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000c400000004000000000000000300050e536d61727450726f6d6f73000100363339313735343333363033004000000000010008008c0500031606020062007500790069006e0067002000260020006c006f006100640069006e006700200061006e007900200053004d004100520054002c00200054004e0054002c00200026002000530055004e002000700061007200740069006300690070006100740069006e0067002000700072006f006400750063007400730020006f006e006c00790020' (196 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000033030303030303845334300' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
3
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000c400000004000000000000000400050e536d61727450726f6d6f73000100363339313735343333363033004000000000010008008c0500031606030069006e00200053004d002c00200053006100760065006d006f00720065002c002000480079007000650072006d00610072006b00650074002c002000570061006c007400650072006d006100720074002c0020002600200041006c00660061006d00610072007400200066006f00720020006d006f007200650020006300680061006e0063' (196 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000043030303030303845334400' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
4
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000c400000004000000000000000500050e536d61727450726f6d6f73000100363339313735343333363033004000000000010008008c0500031606040065007300200074006f002000770069006e002000610020005000310030002c00300030003000200053004d002000530068006f007000700069006e0067002000730070007200650065002e002000500072006f006d006f002000720075006e007300200041007500670031002d0053006500700033003000200032003000310039002e0020' (196 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000053030303030303845334500' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
5
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'000000c400000004000000000000000600050e536d61727450726f6d6f73000100363339313735343333363033004000000000010008008c0500031606050044005400490020002300200078007800780078002e00200046006f00720020006d006f0072006500200069006e0066006f002000760069007300690074002000780078007800780078002e002000410063006300650073007300200074006f002000740068006900730020007300690074006500200069007300200046005200450045002e' (196 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'0000001b8000000400000000000000063030303030303845334600' (27 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
6
DEBUG:smpplib.client:Sending submit_sm PDU
DEBUG:smpplib.client:>>b'0000006400000004000000000000000700050e536d61727450726f6d6f73000100363339313735343333363033004000000000010008002c05000316060600a0002000540068006900730020006d0073006700200069007300200046005200450045002e' (100 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'00000010800000040000001400000007' (16 bytes)
DEBUG:smpplib.client:Read submit_sm_resp PDU
7
INFO:smpplib.client:Disconnecting...
WARNING:smpplib.client:<smpplib.client.Client object at 0x7f16ca442d68> is disconnecting in the bound state

smpp client time out

DEBUG:smpplib.client:Read submit_sm_resp PDU
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:Socket timeout, listening again
DEBUG:smpplib.client:Sending enquire_link PDU
DEBUG:smpplib.client:>>b'00000010000000150000000000000003' (16 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<b'00000010800000150000000000000003' (16 bytes)
DEBUG:smpplib.client:Read enquire_link_resp PDU
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:Socket timeout, listening again
DEBUG:smpplib.client:Sending enquire_link PDU

Hi i got this loop log and dont stop whats the problem?

Suggested modification of sample code: "listen in a thread"

from threading import Thread t = Thread(target=client.listen) t.start()
I used the code in the example to implement the function of sending SMS in django, but when listen() throws an exception, the thread terminates and the enquire_link packet loss, it will causes the server unbind.
My uwsgi server threads are set to 4, and 4 threads constantly rebind the server, it will resulting whith similar errors like: smpplib. exceptions. UnknownCommand Error: Unknown SMPP command code "0x428"

So,would the following modifications be better?
`
def listen():
while True:
try:
ecarxsmpp.client.listen()
except Exception:
print traceback.format_exc()

t = Thread(target=listen)
t.start()
`

Unknown SMPP command code "0x428"

I could send SMS using the example code given in the github

But, Getting following errors at the end.

('====pdu.sequence======', 1)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<0000003a80000004000000000000000133346630616331622d613131642d343137622d383730622d666562303435636664633333000428000100 (58 bytes)
Traceback (most recent call last):
  File "test2.py", line 41, in <module>
    client.listen()
  File "build/bdist.linux-x86_64/egg/smpplib/client.py", line 247, in listen
  File "build/bdist.linux-x86_64/egg/smpplib/client.py", line 190, in read_pdu
  File "build/bdist.linux-x86_64/egg/smpplib/smpp.py", line 46, in parse_pdu
  File "build/bdist.linux-x86_64/egg/smpplib/pdu.py", line 134, in parse
  File "build/bdist.linux-x86_64/egg/smpplib/command.py", line 328, in parse_params
  File "build/bdist.linux-x86_64/egg/smpplib/command.py", line 355, in parse_optional_params
  File "build/bdist.linux-x86_64/egg/smpplib/command.py", line 73, in get_optional_name
smpplib.exceptions.UnknownCommandError: Unknown SMPP command code "0x428"
DEBUG:smpplib.client:Sending unbind PDU
DEBUG:smpplib.client:>>00000010000000060000000000000001 (16 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<00000010800000060000000000000001 (16 bytes)
DEBUG:smpplib.client:Read unbind_resp PDU
INFO:smpplib.client:Disconnecting...

Long message decode error! some optional params can't decode

By catching a bag,Those optional params are located between field 'sm_length' and 'short_message', 6 byte size.
There are 6 bytes of random code on the head of field 'short_message' !
Net packet:
GSM Short Message Service User Data
UDH Length: 5
IE Id: SMS - Concatenated short messages, 8-bit reference number (0x00): message 6, part 2 of 2
Message identifier: 6
......
Could you help me?

Can't decode cyrilic symbols

After attaching a handler on received sms. I parse out sms body from:

def on_receive(pdu):
    """This function is called when new sms is received"""
    source = pdu.source_addr

    message = pdu.short_message


    received = str(datetime.now().isoformat())
    logger.info('SOURCE:"{}" | MSG:"{}" '.format(source, message))

sms text = "ше_machines_ше"
printed sms output = ??machines??

The issue occurs when I parse out the data to a message variable. If I try printing that data I get question marks. What should be done to get the correct symbols?

Problem with some symbols @ _ $

I am using the latest(master) version of the library.
Mainly sending English & Bengali sms.

Everything is working fine, even complex Bengali symbols are being nicely sent but specific symbols are not being sent correctly.
Three known symbols:
@ _ $
These symbols are sent as ¿.

Code attached:

    parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(messageBody)
    pdus = ""

    try:
        for part in parts:
            pdu = client.send_message(
                source_addr_ton=smpplib.consts.SMPP_TON_INTL,
                # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                # Make sure it is a byte string, not unicode:
                source_addr=sender,

                dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
                # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                # Make sure thease two params are byte strings, not unicode:
                destination_addr=reciever,
                short_message=part,

                data_coding=encoding_flag,
                esm_class=msg_type_flag,
                registered_delivery=True,
            )
            pdus = pdus + " " + str(pdu.sequence) + ","
... ...

How to map PDU with failed status from submit_sm_resp back to request?

We've been using our own fork of this library for a few years now and I'm trying to see if we can move back to using the main repo again. There is one blocker that I cannot yet figure out.

When a submit_sm_resp contains a SMPP error, this could indicate the status of the preceding submit_sm request we sent to the SMSC. However looking at your current implementation, it seems that a PDUError would be raised upon receiving such a 'failed' response that only contains the command name and SMPP status. Apart from potentially killing a listening loop, I don't see how this allows us to know what request this was a response to? And so how would we know that a certain SMS failed to be posted, given that it is async.

Not sure if it is uncommon for the SMPP status field to be used to indicate the submission failure, but our telco's SMSC certainly does this. Also looking at the different status values, this doesn't seem that weird to me.

  1. How would you handle this?
  2. Is there a good reason why the exception does not just include the entire PDU object or otherwise at least the sequence number? So when the exception bubbles up there can be logic processing the sending failure.

Help is much appreciated.

Encoding issue with Hebrew text

Dear,
We are getting an encoding error when we try to send messages in Hebrew. We tried using the example you provided. It works for Russian (the one you provided) but for Hebrew it raises the following exception. Is it Hebrew supported?

Thanks,
Best Regards,
Santiago

  File "/home/sgilabert/git/server/smpplib/client.py", line 321, in send_message
    self.send_pdu(ssm)
  File "/home/sgilabert/git/server/smpplib/client.py", line 172, in send_pdu
    generated = p.generate()
  File "/home/sgilabert/git/server/smpplib/pdu.py", line 142, in generate
    body = self.generate_params()
  File "/home/sgilabert/git/server/smpplib/command.py", line 150, in generate_params
    body += value
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd4 in position 1: ordinal not in range(128)

HEBREW EXAMPLE THAT FAILS

      parts, encoding_flag, msg_type_flag = gsm.make_parts(u'ה נשמע ח')
      client = smpplib.client.Client(host, port)
      client.connect()
      client.bind_transmitter(system_id=system_id, password=pass, system_type=sys_type)
      .
      .
      .
      for part in parts:
        client.send_message(
          source_addr_ton = source_ton,
          source_addr_npi = source_npi,
          source_addr = source_addr,
          dest_addr_ton = dest_ton,
          dest_addr_npi = dest_npi,
          short_message=part,
          data_coding=encoding_flag,
          esm_class=msg_type_flag,
        )

RUSSIAN EXAMPLE THAT WORKS

      parts, encoding_flag, msg_type_flag = gsm.make_parts(u'Привет мирח')
      client = smpplib.client.Client(host, port)
      client.connect()
      client.bind_transmitter(system_id=system_id, password=pass, system_type=sys_type)
      .
      .
      .
      for part in parts:
        client.send_message(
          source_addr_ton = source_ton,
          source_addr_npi = source_npi,
          source_addr = source_addr,
          dest_addr_ton = dest_ton,
          dest_addr_npi = dest_npi,
          short_message=part,
          data_coding=encoding_flag,
          esm_class=msg_type_flag,
        )

function make_parts_encoded work not correct

I've tried send u'Привет мир!\n'*10 got 4 part message.
But result correct is fit two parts.

Constants

UCS2_SIZE = 70
UCS2_MP_SIZE = UCS2_SIZE - 3
>>> import smpplib.gsm
>>> text = u'Привет мир!\n'*10
>>> len(text)
120
>>> 120 / (70 - 3)
1.791044776119403
>>> parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text)
>>> len(parts)
4

Looks like it is a result of encoded text is more long.

Line Break

I'm trying to send the message with line breaks between the lines. The message is sent over but without line breaks (new lines). I've tried "/n" , "/r" , %0A but didn't work any of these...Appreciate if you could help me with the issues.

Message no sent

Hi,

When I used the one from https://code.google.com/p/smpplib/, the message is sent. But when I used this one, no message is sent. I don't see any error neither. This is happening for non-unicode messages.

Any extra parameters I should set set?

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in position 120: ordinal not in range(128)

  1. The code which you have given will send unicode text as message but how can i send a normal text.
    when i send normal text am getting
Traceback (most recent call last):
    client.listen()
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/client.py", line 326, in listen
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/client.py", line 279, in read_once
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/client.py", line 219, in read_pdu
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/smpp.py", line 46, in parse_pdu
    text_type = str(filter(str.isalpha, str(text.encode('utf-8'))))
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/pdu.py", line 133, in parse
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/command.py", line 334, in parse_params
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/command.py", line 349, in parse_optional_params
  File "build/bdist.macosx-10.12-x86_64/egg/smpplib/command.py", line 75, in get_optional_name
smpplib.exceptions.UnknownCommandError: Unknown SMPP command code "0x1402"
DEBUG:smpplib.client:Sending unbind PDU
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:Read unbind_resp PDU
INFO:smpplib.client:Disconnecting...
  1. i need to send normal text, unicode text and \x unicode characters but not as parts. all the text upto the allowed text length have to be sent as a single message else it should throws MessageTooLong but am getting unicodeDecodeError
UnicodeEncodeError: 'ascii' codec can't encode character u'\xef' in position 120: ordinal not in range(128)

connection refused

I get this error I'm using port 2775

Traceback (most recent call last):
  File "gateway.py", line 22, in <module>
    client.connect()
  File "/usr/lib/python2.6/site-packages/python_smpplib-1.0.1-py2.6.egg/smpplib/client.py", line 108, in connect
    raise exceptions.ConnectionError("Connection refused")
smpplib.exceptions.ConnectionError: Connection refused

what can I do to solve it ?

thread not stopping when unbinding

I have implemented a GUI app using the smpplib. for each sent sms I need to display the receipt_id on the screen. it works ok, but when I try to unbind, the thread doesn't stop (connec.listen), the app freezes and becomes not responsive.

DEBUG:root:Read submit_sm_resp PDU from testserver (1525684726.2876072)
DEBUG:root:Waiting for PDU...
DEBUG:root:Unbind client 1525684726.2876072...
DEBUG:root:Sending unbind PDU to testserver (1525684726.2876072)
DEBUG:root:>>b'00000010000000060000000000000003' (16 bytes) (1525684726.2876072)
DEBUG:root:Waiting for PDU...

smpplib.exceptions.PDUError: ('(8) bind_transmitter_resp: System Error', 8)

I am getting the error below without any information to debug

[Sun Jun 02 16:27:10.311791 2019] [:error] [pid 23109] DEBUG:smpplib.client:Sending bind_transmitter PDU
[Sun Jun 02 16:27:10.312102 2019] [:error] [pid 23109] DEBUG:smpplib.client:>>b'0000002700000002000000000000000161657261536f6674006165726173403132000034000000' (39 bytes)
[Sun Jun 02 16:27:10.312259 2019] [:error] [pid 23109] DEBUG:smpplib.client:Waiting for PDU...
[Sun Jun 02 16:27:10.518167 2019] [:error] [pid 23109] DEBUG:smpplib.client:<<b'0000001180000002000000080000000100' (17 bytes)
[Sun Jun 02 16:27:10.518501 2019] [:error] [pid 23109] DEBUG:smpplib.client:Read bind_transmitter_resp PDU
[Sun Jun 02 16:27:10.518665 2019] [:error] [pid 23109] INFO:smpplib.client:Disconnecting...
[Sun Jun 02 16:27:10.541386 2019] [:error] [pid 23109] [remote 154.160.26.113:0] mod_wsgi (pid=23109): Exception occurred processing WSGI script '/opt/python/current/app/wsgi.py'.
[Sun Jun 02 16:27:10.542715 2019] [:error] [pid 23109] DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): sentry.io:443
[Sun Jun 02 16:27:10.544209 2019] [:error] [pid 23109] [remote 154.160.26.113:0] Traceback (most recent call last):
[Sun Jun 02 16:27:10.544379 2019] [:error] [pid 23109] [remote 154.160.26.113:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/sentry_sdk/integrations/flask.py", line 66, in sentry_patched_wsgi_app
client.bind_transmitter(system_id=SMS_TIGO_USERNAME, password=SMS_TIGO_PASSWORD)
[Sun Jun 02 16:27:10.546016 2019] [:error] [pid 23109] [remote 154.160.26.113:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/smpplib/client.py", line 149, in bind_transmitter
[Sun Jun 02 16:27:10.546051 2019] [:error] [pid 23109] [remote 154.160.26.113:0]     return self._bind('bind_transmitter', **kwargs)
[Sun Jun 02 16:27:10.546088 2019] [:error] [pid 23109] [remote 154.160.26.113:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/smpplib/client.py", line 143, in _bind
[Sun Jun 02 16:27:10.546127 2019] [:error] [pid 23109] [remote 154.160.26.113:0]     int(resp.status),
[Sun Jun 02 16:27:10.546177 2019] [:error] [pid 23109] [remote 154.160.26.113:0] smpplib.exceptions.PDUError: ('(8) bind_transmitter_resp: System Error', 8)

can't concat str to bytes

I am getting this error below, everything is working expect this part of the code:

  File "smpplib/client.py", line 347, in send_message
    self.send_pdu(ssm)
  File "smpplib/client.py", line 181, in send_pdu
    generated = p.generate()
  File "smpplib/pdu.py", line 136, in generate
    body = self.generate_params()
  File "smpplib/command.py", line 145, in generate_params
    body += value

python 3 support

Hi, I was trying to use smpplib with python 3 today, and I noticed there were some loines of code which were not compatible with it.

I created a fork with quick fixes for that: https://github.com/pespin/python-smpplib/commits/pespin/devel
Not sure what's the best idea regarding python3 though. Is anybody willing to use it with python2? Can we drop python 2 support or we need to support both somehow?

last 4 bits of incoming pdu is truncated on purpose?

so I was testing receiving deliver_sm as a client and noticed a custom parameter I had introduced had the last 4 characters missing always. and I came across this line in the client.py code:
raw_pdu = self._socket.recv(length - 4)

I have updated it to
raw_pdu = self._socket.recv(length)
and now the full parameter data is received alright. but does anyone know why it was there in the first place? I don't want to launch and have problems later.
or if it is okay like this then I will leave it like that.

Problems when unbinding

Hi,

I am currently reading 12 bytes from unbind PDU Response, when I should in fact read 16 bytes. I also check the pcap packets and the information is there.

Here is the debug trace:

SEND BIND
DEBUG:smpplib.client:Sending bind_transceiver PDU
DEBUG:smpplib.client:>>000000250000000900000000000000014d324d004d65646f31735700534d50500034000000 (37 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<0000001780000009000000000000000130000210000134 (23 bytes)
DEBUG:smpplib.client:Read bind_transceiver_resp PDU
DEBUG:smpplib.client:Waiting for PDU...

SEND UNBIND
DEBUG:smpplib.client:>>00000010000000060000000000000001 (16 bytes)
DEBUG:smpplib.client:Waiting for PDU...
DEBUG:smpplib.client:<<000000100000000000000001 (12 bytes)

INFO:werkzeug:127.0.0.1 - - [03/Mar/2016 17:45:24] "GET /close-app/ HTTP/1.1" 200 -
ERROR
:smpp-app.SMPPApp: Unknown SMPP command code '0x0' - Continue operating.: 
 Traceback (most recent call last):
  File "/home/m2m/smpp-app/SMPPApp.py", line 78, in listen
    client.listen()
  File "/home/Envs/dev1/lib/python2.7/site-packages/smpplib/client.py", line 275, in listen
    p = self.read_pdu()
  File "/home/Envs/dev1/lib/python2.7/site-packages/smpplib/client.py", line 218, in read_pdu
    p = smpp.parse_pdu(raw_pdu, client=self)
  File "/home/Envs/dev1/lib/python2.7/site-packages/smpplib/smpp.py", line 40, in parse_pdu
    command = pdu.extract_command(data)
  File "/home/Envs/dev1/lib/python2.7/site-packages/smpplib/pdu.py", line 38, in extract_command
    return command_codes.get_command_name(code)
  File "/home/Envs/dev1/lib/python2.7/site-packages/smpplib/command_codes.py", line 46, in get_command_name
    "'0x%x'" % code)
UnknownCommandError: Unknown SMPP command code '0x0'

DEBUG:smpplib.client:Waiting for PDU...
INFO:smpplib.client:Connecting to 10.5.13.13:38116...

I printed the length variable in read_pdu and is also 16.


Here is the pcap packets from the unbind transaction:

Frame 317: 82 bytes on wire (656 bits), 82 bytes captured (656 bits)
Transmission Control Protocol, Src Port: 36097 (36097), Dst Port: 38116 (38116), Seq: 54, Ack: 40, Len: 16
Short Message Peer to Peer, Command: Unbind, Seq: 1, Len: 16
    Length: 16
    Operation: Unbind (0x00000006)
    Sequence #: 1

Frame 318: 82 bytes on wire (656 bits), 82 bytes captured (656 bits)
Transmission Control Protocol, Src Port: 38116 (38116), Dst Port: 36097 (36097), Seq: 40, Ack: 70, Len: 16
Short Message Peer to Peer, Command: Unbind - resp, Status: "Ok", Seq: 1, Len: 16
    Length: 16
    Operation: Unbind - resp (0x80000006)
    Result: Ok (0x00000000)
    Sequence #: 1

Problem with encoding

I have a problem with long messages(>40 symblos) in russian:

DEBUG - Traceback (most recent call last):
File "smpp_sender_new.py", line 375, in send_next_message
self.smpp_client.send_message(message)
File "smpp_sender_new.py", line 304, in send_message
registered_delivery=True,
File "smpp_sender_new.py", line 181, in send_message
ssm = super(SMPPWrapper, self).send_message(**kwargs)
File "/home/iz/test/smpplib/client.py", line 293, in send_message
self.send_pdu(ssm)
File "/home/iz/test/smpplib/client.py", line 144, in send_pdu
generated = p.generate()
File "/home/iz/test/smpplib/pdu.py", line 143, in generate
body = self.generate_params()
File "/home/iz/test/smpplib/command.py", line 141, in generate_params
body += value
UnicodeDecodeError: 'ascii' codec can't decode byte 0x86 in position 0: ordinal not in range(128)

Tried decode, encode on original string and on body/value in command.py. String is displayed in the log with no errors.
Example string: 'Обрыв оптоволоконного кабеля. Ремонтные работы в течение дня.'
Python 2.7.4.
With message from example similar problem.

Getting message received event infinitly

Thank you for this powerful application.

I just tried this code and made bid change ie executed the thread to listen for the incoming message , when one sends message, it executes _message_received function . At the end I just called send_message function. The code is working but on my 1st message send and receives it again receiving my previous message and again executes _message_received function and send message.
This process continues till I stops the script execution.

def _message_received(self, p):
        """Handler for received message event"""

        self.message_received_handler(pdu=p)
        dsmr = smpp.make_pdu('deliver_sm_resp', client=self)
        #, message_id=args['pdu'].sm_default_msg_id)
        dsmr.sequence = p.sequence
        self.send_pdu(dsmr)
        print "My message:"
        print p.short_message
        print "My number:"
        print p.source_addr

        sendXML = test_xmphttp.SendXMLHTTP()
        # print dir(sendXML)
        getStatus = sendXML.sendXMLPost(p.source_addr,p.short_message)

        print getStatus
        if(getStatus['status'] == 'success'):
            parts, encoding_flag, msg_type_flag = gsm.make_parts(getStatus['data'])

            # for part in parts:
            for part in parts:

                self.send_message(
                    source_addr_ton=consts.SMPP_TON_INTL,
                    # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                    source_addr='55555',
                    dest_addr_ton=consts.SMPP_TON_INTL,
                    # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
                    destination_addr=p.source_addr,
                    short_message=part,
                    data_coding=encoding_flag,
                    esm_class=msg_type_flag,
                    registered_delivery=True,
                )
                # print(pdu.sequence)

Can you please help me to get the solution.
Thank you,

How to read message with special characters (#@$!)

Thank you for this library. I am trying to read message with:

def received_handler(pdu):
    print ("delivered: {} {} {}".format( pdu.receipted_message_id, pdu.short_message, pdu.source_addr)) 

Receiving a message like "Short message" is working fine but when I receive a french word or an sms with special characters (#@$!) the message is coming with this encoding:

\x00S\x00o\x00m\x00e\x00 \x00w\x00e\x00i\x00r\x00d\x00 \x00c\x00a\x00r\x00a\x00c\x00t\x00e\x00r\x00s\x00 \x00%\x00#\x00 \x00*\x00 \x00\xe9\x00 \x00\xa3\x00 \x00\xe2\x00\xe6\x00 \x00\xeb\x01\x19\x00

I have tried using pdu.short_message.decode() but its not working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.