adein / hangouts_to_sms

Google Hangouts SMS/MMS to XML converter
MIT License
31 stars 11 forks source link

hangouts_to_sms.py stops with type error #12

Open vrl2 opened 6 years ago

vrl2 commented 6 years ago

Thanks for creating this handy tool! I'm experiencing some errors running the script (python 3.6, High Sierra), and was wondering if anyone had any insights. I've made sure that Hangouts.json (is in the same directory as the script, and I've edited my phone number in hangouts_to_sms.py (format "+18005551212"). I have also made the changes to lines 25, 27, and 57 of hangouts_parser.py suggested by onemodtwo (https://github.com/adein/hangouts_to_sms/issues/8), and now it says that it successfully parses the Hangouts data. Hangouts.json is 189M, and the script generates messages.xml (22M). However, it stops with a TypeError when converting the SMS export file:

$ python3.6 hangouts_to_sms.py Parsing Hangouts data file... Done. Converting to SMS export file... Traceback (most recent call last): File "hangouts_to_sms.py", line 18, in titanium_output.create_output_file(conversations, self_gaia_id, OUTPUT_FILE) File "/Users/venkat/Desktop/hangouts_to_sms-develop/titanium_backup_formatter.py", line 74, in create_output_file content_is_plain = self._is_ascii(message.content) File "/Users/venkat/Desktop/hangouts_to_sms-develop/titanium_backup_formatter.py", line 173, in _is_ascii return len(text) == len(text.encode()) TypeError: object of type 'NoneType' has no len()

Thanks!

mrdehate commented 6 years ago

Hey! I ran into the exact same issue as you above, and I think I've worked around it. I've got a limited development background - not at all in Python - so I'm not 100% sure what I'm doing here, but I thought I'd pass around my steps in case it helps get you unstuck. And to prove that it is possible!! :)

First, a change in titanium_backup_formatter.py - I've replaced lines 78, 79, and 80 -

message_string += ">{}".format(
    escape(message.content) if content_is_plain
    else self._base64_text(message.content))

with the following three lines:

message_string += ">"
if message.content is not None:
    message_string += "{}".format(escape(message.content) if content_is_plain else self._base64_text(message.content))

Basically I added another "if not none" check in there, and smushed the last line all onto one. After making this change (and of course, the other ones you've already listed), I finally was able to get the script to run for me.

However, it wasn't the end of the road. Trying to import via Titanium Backup, the app would crash every time. Turns out, it was the same records that were causing the original problem. In my case, I had a bunch of empty <sms> records with no content in them. These particular tags didn't have "encoding" attributes; maybe that's required for titanium backup? I'm not sure.

If I deleted these records from the output messages.xml file, I was able to import everything successfully.

One last thing - right at the top of the the messages.xml file, the "count" attribute of the <threads> tag was wrong. Not sure how much that matters to Titanium Backup, but I did update it manually with the total number of <thread> tags in the file to be safe.