slackapi/python-slack-events-api

SSL Issue(?) when running on GAE Standard

JamieSinn opened this issue · 4 comments

Description

Fails to respond/create request to reply to slack when running on GAE Standard with a Flask backend.

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

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackeventsapi version: 2.0.0
python version: 2.7
OS version(s): Google App Engine Standard

Steps to reproduce:

  1. Send an api call to "conversations.open" when passing in a user received from the "app_mention" event.
  2. Error
    (Relevant code):
@slack_events_adapter.on("app_mention")
 def mention_bot(data):
     logging.info(data)
     event = data["event"]
     user= event["user"]
     channel = event["channel"]
     logging.info(event)
     logging.info(user)
     dm_data = slack_client.api_call(
         "conversations.open",
         users="{0}".format(user))

Expected result:

Conversation to be opened without issue

Actual result:

Failed to open conversation

Stack Trace below

Attachments:

Exception on /slack/events [POST] (/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py:1761)
Traceback (most recent call last):
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackeventsapi/server.py", line 120, in event
    self.emitter.emit(event_type, event_data)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/pyee/__init__.py", line 151, in emit
    result = f(*args, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/main.py", line 35, in mention_bot
    users=user)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/client.py", line 184, in api_call
    self.token, request=method, timeout=timeout, **kwargs
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/server.py", line 349, in api_call
    response = self.api_requester.do(token, request, kwargs, timeout=timeout)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/slackrequest.py", line 84, in do
    return self.post_http_request(token, request, post_data, files, timeout, domain)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/slackclient/slackrequest.py", line 116, in post_http_request
    proxies=self.proxies
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "/base/data/home/apps/k~otr-bots/20181206t214742.414504843222318338/lib/urllib3/connection.py", line 304, in connect
    if self._tunnel_host:
AttributeError: 'VerifiedHTTPSConnection' object has no attribute '_tunnel_host'

Hi @JamieSinn, Thanks for writing in and letting us know about this issue. I've not been able to find a root cause yet, but I'm still looking into it. I'll post back soon.

Thanks!

I'd hate to have to re-write this in a different language because of this.

Jamie, I checked out your code on Github in an unsuccessful attempt to reproduce the the exact error that you were getting. In the process however I discovered an existing issue on Stack Overflow that seemed highly related to the stack trace you've posted above.

The following work around is also suggested on Google's App Engine docs.

from slackeventsapi import SlackEventAdapter
# slackclient depends on requests; ensure requests_toolbelt is imported afterwards.
from slackclient import SlackClient
import requests_toolbelt.adapters.appengine

# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt.adapters.appengine.monkeypatch()

# The rest of your code below

I'd love to know if this solves the problem you're facing. That being said, I've still not been able to find any issues in this project that would cause this error. Opening an issue with Google may yield to more information to your cause.

Weird, my comment didn't post...

Anyway, thank you a ton @RodneyU215! The workaround did work!
I oddly couldn't find the stack article you found, or the GAE docs when debugging. Much appreciated!

Maybe this is something to add to the readme?