KermMartian / smsxml2html

Turn SMS Backup & Restore SMS XML files into HTML transcripts
BSD 3-Clause "New" or "Revised" License
23 stars 8 forks source link

Error #3

Open UstedLoco opened 2 years ago

UstedLoco commented 2 years ago

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

KermMartian commented 2 years ago

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

UstedLoco commented 2 years ago

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

UstedLoco commented 1 year ago

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

ackermanaviation commented 1 year ago

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.

UstedLoco commented 1 year ago

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 commented 1 year ago

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.