hfaran / slack-export-viewer

A Slack Export archive viewer that allows you to easily view and share your Slack team's export
https://pypi.python.org/pypi/slack-export-viewer
MIT License
908 stars 192 forks source link

Execution fails with KeyError: 'replies' #121

Closed pkaldis closed 2 years ago

pkaldis commented 4 years ago

Running the viewer against our data export takes a bit of time, but eventually it exits with the following error:

pkaldis@anatomy ~/Desktop/Export --> slack-export-viewer -z data_export.zip /var/folders/gt/f1j5l07n1zd6_3r_7rz6jgzc0001g1/T/_slackviewer/90d4e276bb39a4adce4ff381bf0ce8bef12e7bf6 already exists Traceback (most recent call last): File "/usr/local/bin/slack-export-viewer", line 11, in sys.exit(main()) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 764, in call return self.main(args, kwargs) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke return callback(args, **kwargs) File "/usr/local/lib/python2.7/site-packages/slackviewer/main.py", line 61, in main configure_app(app, archive, channels, no_sidebar, no_external_references, debug) File "/usr/local/lib/python2.7/site-packages/slackviewer/main.py", line 24, in configure_app top.channels = reader.compile_channels(channels) File "/usr/local/lib/python2.7/site-packages/slackviewer/reader.py", line 35, in compile_channels return self._create_messages(channel_names, channel_data) File "/usr/local/lib/python2.7/site-packages/slackviewer/reader.py", line 176, in _create_messages chats = self._build_threads(chats) File "/usr/local/lib/python2.7/site-packages/slackviewer/reader.py", line 199, in _build_threads for reply in message._message['replies']: KeyError: 'replies'

Any insights on how to troubleshooting this would be greatly appreciated.

Thank you!

coreydeli commented 4 years ago

Same issue here running python 2.7 and 3.6

hfaran commented 4 years ago

Schema might have changed in the export - can you put a breakpoint there to see what keys are in the dictionary to figure out what it might have changed to?

coreydeli commented 4 years ago
/tmp/_slackviewer/26b10a07947e773d8f07e2e3503d54a317f0256f already exists
Traceback (most recent call last):
  File "/home/username/.local/bin/slack-export-viewer", line 11, in <module>
    sys.exit(main())
  File "/home/username/.local/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/username/.local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/username/.local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/username/.local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/username/.local/lib/python3.6/site-packages/slackviewer/main.py", line 61, in main
    configure_app(app, archive, channels, no_sidebar, no_external_references, debug)
  File "/home/username/.local/lib/python3.6/site-packages/slackviewer/main.py", line 24, in configure_app
    top.channels = reader.compile_channels(channels)
  File "/home/username/.local/lib/python3.6/site-packages/slackviewer/reader.py", line 35, in compile_channels
    return self._create_messages(channel_names, channel_data)
  File "/home/username/.local/lib/python3.6/site-packages/slackviewer/reader.py", line 176, in _create_messages
    chats = self._build_threads(chats)
  File "/home/username/.local/lib/python3.6/site-packages/slackviewer/reader.py", line 199, in _build_threads
    for reply in message._message['replies']:
KeyError: 'replies'
landonepps commented 4 years ago

I changed line 199 to: for reply in message._message.get('replies', []): just as a quick patch.

blacky14 commented 4 years ago

the thread replies are no longer embedded in the messages themselves.

they are now separate messages/blocks that are correlated via the thread_ts values, as also explained here: https://api.slack.com/messaging/retrieving#finding_threads

fzimmermann89 commented 4 years ago

While looking at this, I noticed what I think might another bug/potential bug: https://github.com/hfaran/slack-export-viewer/blob/af67f79f0968b4f8981ab96468b62a816be82b87/slackviewer/reader.py#L203 followed by https://github.com/hfaran/slack-export-viewer/blob/af67f79f0968b4f8981ab96468b62a816be82b87/slackviewer/reader.py#L210

The for loop goes through an list and inside the body of the loop elements are removed from the list. wouldn't this cause messages to be skipped?