ownaginatious / fbchat-archive-parser

An application for parsing chat history from a Facebook data archive.
MIT License
312 stars 38 forks source link

Python 2 Unicode Character Error #18

Closed Seanny123 closed 7 years ago

Seanny123 commented 7 years ago

Got the following error in Python 2:

UnicodeEncodeErrorTraceback (most recent call last)
/usr/local/bin/fbcap in <module>()
      9     sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
     10     sys.exit(
---> 11         load_entry_point('fbchat-archive-parser', 'console_scripts', 'fbcap')()
     12     )

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/main.pyc in main()
    151 def main():
    152     try:
--> 153         app.run()
    154     except clip.ClipExit:
    155         pass

/usr/local/lib/python2.7/dist-packages/clip.pyc in run(self, tokens)
    650                         tokens = shlex.split(tokens)
    651                 try:
--> 652                         self.invoke(self.parse(tokens))
    653                 finally:
    654                         self.reset()  # Clean up so the app can be used again

/usr/local/lib/python2.7/dist-packages/clip.pyc in invoke(self, parsed)
    632         '''
    633                 self._ping_main()
--> 634                 self._main.invoke(parsed)
    635 
    636         def reset(self):

/usr/local/lib/python2.7/dist-packages/clip.pyc in invoke(self, parsed)
    517         def invoke(self, parsed):
    518                 # First invoke this command's callback
--> 519                 self._callback(**{k: v for k, v in iteritems(parsed) if k not in self._subcommands})
    520                 # Invoke subcommands (realistically only one should be invoked)
    521                 for k, v in iteritems(parsed):

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/main.pyc in fbcap(path, thread, format, nocolor, timezones, utc, noprogress)
     96             generate_stats(fbch, sys.stdout)
     97         else:
---> 98             write(format, fbch)
     99 
    100     except AmbiguousTimeZoneError as atze:

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/writers/__init__.pyc in write(format, data)
     16                                           % format)
     17     item = getattr(writer_type, "%sWriter" % (format[0].upper() + format[1:]))
---> 18     item().write(data)

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/writers/writer.py in write(self, data)
     13     def write(self, data):
     14         if isinstance(data, FacebookChatHistory):
---> 15             return self.write_history(data)
     16         elif isinstance(data, ChatThread):
     17             return self.write_thread(data)

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/writers/csv.py in write_history(self, history, stream, writer)
     32             writer = self.get_writer(stream, True)
     33         for k in history.threads.keys():
---> 34             self.write_thread(history.threads[k], writer=writer)
     35 
     36     def write_thread(self, thread, stream=sys.stdout, writer=None):

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/writers/csv.py in write_thread(self, thread, stream, writer)
     38             writer = self.get_writer(stream, True)
     39         for message in thread.messages:
---> 40             self.write_message(message, thread, writer=writer)
     41 
     42     def write_message(self, message, parent=None, stream=sys.stdout,

/home/sean/git/fbchat-archive-parser/fbchat_archive_parser/writers/csv.py in write_message(self, message, parent, stream, writer)
     52             row[THREAD_ID_KEY] = "<unknown>" if not parent \
     53                                  else ", ".join(parent.participants)
---> 54         writer.writerow(row)

/usr/lib/python2.7/csv.pyc in writerow(self, rowdict)
    150 
    151     def writerow(self, rowdict):
--> 152         return self.writer.writerow(self._dict_to_list(rowdict))
    153 
    154     def writerows(self, rowdicts):

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa5' in position 1: ordinal not in range(128)

This error does not occur in Python3.

ownaginatious commented 7 years ago

Thanks for reporting this! Should be fixed now in master and in version 0.8.post6 on PyPI.