Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSM.decode strange result #8

Closed
SummerSeaSun opened this issue Mar 23, 2022 · 2 comments
Closed

GSM.decode strange result #8

SummerSeaSun opened this issue Mar 23, 2022 · 2 comments
Labels
question Further information is requested

Comments

@SummerSeaSun
Copy link

Hi,
I've tried with python3.10 but you can see that Out[4 ] is pretty strange as result, any idea on how to fix this?

In [1]: from smspdudecoder.codecs import GSM, UCS2


In [2]: GSM.decode(GSM.encode('1234567', with_padding=True), strip_padding=True)
Out[2]: '1234567'


In [4]: GSM.decode('07919333851805420406D0D4641300002220720171424087C7B29B9E6697416376BAECA69759206AB2099A068D45D0B52804D1E561D00D744EBFE5EE34081
   ...: E9ECFCBF23F280C8287CFE176D94D7F83C66F37A8EE068DC3EEB7BB0C22A741F3373B', strip_padding=True)
Out[4]: 'ì"NÆSΔF$BòΣ@MΞYÇ@@ò£".¡8B@æ<,v&Of.ùΞfN.v&/f$"MlèΞ\r4,è:-Λè"Ψåù:¥:NüΠwNù$åßÉ/Πàì\nù$å>Ån.v&àùΞüvù*wùΞÅvüv.ù"NùΞàf'

I've tried out also python-messaging that output an expected readable result of Out[4]:

In [1]: from messaging.sms import  SmsDeliver

In [2]: pdutext='07919333851805420406D0D4641300002220720171424087C7B29B9E6697416376BAECA69759206AB2099A068D45D0B52804D1E561D00D744EBFE5EE34081E9ECFCBF23F280C8287CFE176D
   ...: 94D7F83C66F37A8EE068DC3EEB7BB0C22A741F3373B'

In [3]: x=SmsDeliver(pdutext)

In [4]: x.text
Out[4]: 'Gentile cliente, TIM SAFE WEB tra 7 giorni passerà a pagamento con un canone di sol'
@alexpirine
Copy link
Member

alexpirine commented Mar 23, 2022

Hello,

GSM and UCS2 are string codecs, just like ASCII, ISO-885-1, UTF-8, and so on.

So they are only relevant to encode and decode text.

The payload you are providing seems to be an SMS Deliver PDU - it's a binary payload containing various fields describing an incoming SMS message, text content being just one of them.

This library does not have a very good high level API to decode PDUs yet, but there is a shortcut available that you can use:

>>> from smspdudecoder.easy import *
>>> easy_sms('07919333851805420406D0D4641300002220720171424087C7B29B9E6697416376BAECA69759206AB2099A068D45D0B52804D1E561D00D744EBFE5EE34081E9ECFCBF23F280C8287CFE176D94D7F83C66F37A8EE068DC3EEB7BB0C22A741F3373B')
{
  'sender': 'TIM',
  'date': datetime.datetime(2022, 2, 27, 9, 17, 24, tzinfo=datetime.timezone.utc),
  'content': 'Gentile cliente, TIM SAFE WEB tra 7 giorni passerà a pagamento con un canone di sol',
  'partial': False,
}

@alexpirine alexpirine added the question Further information is requested label Mar 23, 2022
@alexpirine
Copy link
Member

Feel free to re-open if you have other questions, @SummerSeaSun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants