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

Ignore https requests #89

Closed tobenary closed 3 years ago

tobenary commented 3 years ago

Description

Sometimes, my bot crashes when someone tries to attempt into the https

Requirements

Bug Report

For example, I'm getting this:

[22/Apr/2021 10:50:38] "GET / HTTP/1.1" 404 -
[22/Apr/2021 10:51:11] code 400, message Bad request syntax
('\x03ÿT\x81`\x00\x00\x00\x00\x00\x00\x00\x..... (I cut the rest )
- [22/Apr/2021 10:51:11] "ÿT`" 400 -
[22/Apr/2021 10:51:11] "GET / HTTP/1.1" 404 -
Exception happened during processing of request from ('x.y.z.39', 55254)
Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 320, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 386, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------
74.120.14.39 - - [23/Apr/2021 03:11:40] code 400, message Bad request version ('À\x14À')
74.120.14.39 - - [23/Apr/2021 03:11:40] "{w´%Âj¦»ºààocess_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 386, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)

Steps to reproduce:

I am not sure how to reproduce it, but it seems that sometimes, the Flask is getting an https request instead of HTTP and crashes.

  1. Is it enough to add SSL_DISABLE=True to the flask app?
  2. Is https://slack.dev/bolt-python/concepts#errors going to resolve this issue?

Expected result:

App stay online 24/7 :)

Ref search:

  1. https://stackoverflow.com/questions/49389535/problems-with-flask-and-bad-request
  2. https://slack.dev/bolt-python/concepts#errors
seratch commented 3 years ago

Hi @tobenary, I'm not sure if this is an expected answer to this but generally speaking, I would recommend running your web apps in a production-ready Python web app server like Gunicorn. With this way, you may have a load balancer or something like that in front of the app server and your app won't be directly exposed to https requests.

seratch commented 3 years ago

Also, if you are working on a new project, we highly recommend using Bolt for Python instead of this library! Bolt offers more functionalities and developing Slack apps would be even easier with it.

tobenary commented 3 years ago

Sorry, I was sure I was writing it on the Bolt board, yes. I use it

tobenary commented 3 years ago

Just an FYI, I google this error and I saw it is related to this: https://github.com/olipo186/Git-Auto-Deploy/issues/221 I edit the FW rules on my ubuntu server and blocked the RDP 3389. Hopefully, I won't have to face those kinds of errors.