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

Error #3

Open
UstedLoco opened this issue Feb 1, 2022 · 6 comments
Open

Error #3

UstedLoco opened this issue Feb 1, 2022 · 6 comments

Comments

@UstedLoco
Copy link

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
Copy link
Owner

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

@UstedLoco
Copy link
Author

UstedLoco commented Feb 2, 2022 via email

@UstedLoco
Copy link
Author

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

@ackermanaviation
Copy link

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
Copy link
Author

UstedLoco commented Dec 24, 2022

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants