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
966 stars 193 forks source link

Error 500 when opening certain channels #107

Open MasterPuffin opened 5 years ago

MasterPuffin commented 5 years ago

I get an error 500 always when I try to open a certain channel. Attached is the log

C:\Users\johan\AppData\Local\Temp\_slackviewer\9265b9f77875483902941ea630bc68385d40046b already exists
 * Serving Flask app "slackviewer.app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://localhost:5000/ (Press CTRL+C to quit)
ERROR:root:unable to find user in [REMOVED FOR PRIVACY]
127.0.0.1 - - [05/Sep/2019 02:05:18] "GET / HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [05/Sep/2019 02:05:18] "GET / HTTP/1.1" 200 -
ERROR:root:unable to find user in [REMOVED FOR PRIVACY]
127.0.0.1 - - [05/Sep/2019 02:05:25] "GET /channel/trashtalk/ HTTP/1.1" 500 -
INFO:werkzeug:127.0.0.1 - - [05/Sep/2019 02:05:25] "GET /channel/trashtalk/ HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
  File "c:\program files (x86)\python\lib\site-packages\werkzeug\serving.py", line 303, in run_wsgi
    execute(self.server.app)
  File "c:\program files (x86)\python\lib\site-packages\werkzeug\serving.py", line 291, in execute
    application_iter = app(environ, start_response)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files (x86)\python\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files (x86)\python\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\app.py", line 26, in channel_name
    no_external_references=app.no_external_references)
  File "c:\program files (x86)\python\lib\site-packages\flask\templating.py", line 140, in render_template
    ctx.app,
  File "c:\program files (x86)\python\lib\site-packages\flask\templating.py", line 120, in _render
    rv = template.render(context)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\templates\viewer.html", line 63, in top-level template code
    {{render_message(message, None, no_external_references)}}
  File "c:\program files (x86)\python\lib\site-packages\jinja2\runtime.py", line 579, in _invoke
    rv = self._func(*arguments)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\templates\util.html", line 22, in template
    {%if message.user.email%} <span class="print-only user-email">({{message.user.email}})</span>{%endif%}
  File "c:\program files (x86)\python\lib\site-packages\jinja2\environment.py", line 430, in getattr
    return getattr(obj, attribute)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\message.py", line 31, in user
    return self._formatter.find_user(self._message)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\formatter.py", line 25, in find_user
    if message.get("subtype", "").startswith("bot_") and message["bot_id"] not in self.__USER_DATA:
KeyError: 'bot_id'
ERROR:werkzeug:Error on request:
Traceback (most recent call last):
  File "c:\program files (x86)\python\lib\site-packages\werkzeug\serving.py", line 303, in run_wsgi
    execute(self.server.app)
  File "c:\program files (x86)\python\lib\site-packages\werkzeug\serving.py", line 291, in execute
    application_iter = app(environ, start_response)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 2449, in wsgi_app
    response = self.handle_exception(e)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1866, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files (x86)\python\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files (x86)\python\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\program files (x86)\python\lib\site-packages\flask\app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\app.py", line 26, in channel_name
    no_external_references=app.no_external_references)
  File "c:\program files (x86)\python\lib\site-packages\flask\templating.py", line 140, in render_template
    ctx.app,
  File "c:\program files (x86)\python\lib\site-packages\flask\templating.py", line 120, in _render
    rv = template.render(context)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "c:\program files (x86)\python\lib\site-packages\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\templates\viewer.html", line 63, in top-level template code
    {{render_message(message, None, no_external_references)}}
  File "c:\program files (x86)\python\lib\site-packages\jinja2\runtime.py", line 579, in _invoke
    rv = self._func(*arguments)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\templates\util.html", line 22, in template
    {%if message.user.email%} <span class="print-only user-email">({{message.user.email}})</span>{%endif%}
  File "c:\program files (x86)\python\lib\site-packages\jinja2\environment.py", line 430, in getattr
    return getattr(obj, attribute)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\message.py", line 31, in user
    return self._formatter.find_user(self._message)
  File "c:\program files (x86)\python\lib\site-packages\slackviewer\formatter.py", line 25, in find_user
    if message.get("subtype", "").startswith("bot_") and message["bot_id"] not in self.__USER_DATA:
KeyError: 'bot_id'
bblising commented 5 years ago

I remember encountering this error. It has to do with the bots. It was easy to solve by adding the missing id into the users.json. Try sending a message to the bot, I think that should add the user. I remember putting a try catch somewhere. I can't find the data with the error anymore so no way to test. I'll try to post the possible solution.

hfaran commented 5 years ago

Would help to add a breakpoint on this line and see what properties message contains. Either the name of the property has changed from "bot_id" to something else or it isn't there at all.

james-storey commented 5 years ago

Running into a similar issue. The message object indeed does not contain a "bot_id" field at all. In my case, the offending message is an imported message that was sent by a bot, but not in slack. So while it is technically a bot message, there is no bot to link an id with.


{
  type: 'message',
  subtype: 'bot_message',
  text: 'Hi',
  ts: '1438879051.000000',
  username: 'HipChat'
}
msiemens commented 4 years ago

I have the same issue, by the way. Adding a check if the bot_id key exists in this line:

https://github.com/hfaran/slack-export-viewer/blob/b5b178fec44a341d14ba1f4a7dc873ae1d923f14/slackviewer/formatter.py#L32

fixes it.