slackapi / python-slack-events-api

Slack Events API adapter for Python (Flask required)
https://api.slack.com/events
MIT License
343 stars 116 forks source link

Exception on receiving new slack events #79

Closed Nalinc closed 4 years ago

Nalinc commented 4 years ago

Description

SlackEventAdapter is throwing an exception on receiving slack events.

[2020-10-13 16:46:54,786] ERROR in app: Exception on /api/slack/events/ [POST]
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/slackeventsapi/server.py", line 97, in event
    self.emitter.emit('error', slack_exception)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 111, in emit
    self._emit_handle_potential_error(event, args[0] if args else None)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
    raise error
slackeventsapi.server.SlackEventAdapterException: Invalid request timestamp

What type of issue is this? (place an x in one of the [ ])

Requirements

Bug Report

Reproducible in:

slackeventsapi version: 2.1.0 python version: 3.6.9 OS version(s): Ubuntu 18.04.4 LTS (Bionic Beaver)

Steps to reproduce:

  1. Create a simple Flask server with SlackEventAdapter
  2. Send a message on slack
  3. Check server console for the error.

Expected result:

No error should be thrown when an event is received from slack (message or reaction).

Actual result:

Error is thrown whenever a slack event is received (message or reaction).

Attachments:

Screencast

ezgif com-gif-maker

Logs
[2020-10-13 16:46:54,786] ERROR in app: Exception on /api/slack/events/ [POST]
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/slackeventsapi/server.py", line 97, in event
    self.emitter.emit('error', slack_exception)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 111, in emit
    self._emit_handle_potential_error(event, args[0] if args else None)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
    raise error
slackeventsapi.server.SlackEventAdapterException: Invalid request timestamp
seratch commented 4 years ago

@Nalinc Hello, thanks for asking the question! The error can be thrown due to either of the following reasons:

https://github.com/slackapi/python-slack-events-api/blob/v2.2.1/slackeventsapi/server.py#L91-L95

I'm guessing the latter one may be the cause of your situation. Could you check the NTP service (the time clock in the system) on the Ubuntu host?

Nalinc commented 4 years ago

Hi @seratch

Thanks for your response. Yes, you're right the issue was caused due to a wide difference in timestamps between the given request and current system time. This happened because our socket server and requesting server were running in different time-zones, resulting in 5+ minutes of difference. Synchronizing the time on the two systems fixed the issue.

rghv-cwx commented 3 weeks ago

@Nalinc I am facing the same issue, and not able to figure out the solution. Can you please provide the required help ?