smsxml2html icon indicating copy to clipboard operation
smsxml2html copied to clipboard

Error

Open UstedLoco opened this issue 3 years ago • 6 comments

Hello, I hope this is the right place for this. I don't know much about Github or Python.

I attempted to run this on an couple of existing xml backups I have. I get the following:

Parsing conversations from sms-20170620140713.xml
Traceback (most recent call last):
  File "D:\sms\smsxml2html.py", line 246, in <module>
    main()
  File "D:\sms\smsxml2html.py", line 237, in main
    messages += parseConversations(root, conversations, users, args.output, carrier_number)
  File "D:\sms\smsxml2html.py", line 104, in parseConversations
    save_msg = SMSMsg(date, body, type_, {})
  File "D:\sms\smsxml2html.py", line 55, in __init__
    self.text = text.decode('utf8')
AttributeError: 'str' object has no attribute 'decode'

Is this possible to remedy and get it to work? Thank you

UstedLoco avatar Feb 01 '22 07:02 UstedLoco

Hi there, are you using Python 2.x or Python 3.x?

KermMartian avatar Feb 01 '22 21:02 KermMartian

Hi Christopher, thanks for replying. I’m using Python 3.9.

UstedLoco avatar Feb 02 '22 21:02 UstedLoco

Hey, just following up on this. Any chance you could advise?

UstedLoco avatar Oct 23 '22 23:10 UstedLoco

The code is written for python 2. If you want to use python 3, you'll need to update the code or use a fork of the code that someone has already updated.

https://github.com/samling/smsxml2html looks like it may work for python 3

Alternatively, my fork: https://github.com/ackermanaviation/smsxml2html also works with python 3. But I've made more changes to fix some bugs, With more changes, it's also more likely I've broken something. It hasn't been tested outside of my personal files.

ackermanaviation avatar Dec 24 '22 04:12 ackermanaviation

Thanks for the reply! Tried both of your suggestions, they both give me this error:

Traceback (most recent call last):
  File "D:\sms\smsxml2html.py", line 244, in <module>
    main()
  File "D:\sms\smsxml2html.py", line 238, in main
    files = dumpConversations(args.output, conversations, carrier_number)
  File "D:\sms\smsxml2html.py", line 192, in dumpConversations
    f.write('<td><b><span class="msg_date">%s</span></td><td><span class="msg_sender_%s">%s %s</span></b></td><td>%s' % (dt.strftime('%m/%d/%y %I:%M:%S%p'), msg.type_, '<<' if msg.type_ == "1" else '>>', (msg.contact_name if msg.contact_name is not None else address) if msg.type_ == "1" else "You", msg.text))
  File "C:\Users\J\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 118-119: character maps to <undefined>

UstedLoco avatar Dec 24 '22 11:12 UstedLoco

Looks like I sorted it by adding the encoding parameter to with open(output_path, 'w', encoding="utf-8") as f: It now outputs the html files. This is with the Samling one but I suspect it would be the same with yours.

UstedLoco avatar Dec 24 '22 11:12 UstedLoco