WebexCommunity / WebexPythonSDK

Work with the Webex APIs in native Python!
https://webexcommunity.github.io/WebexPythonSDK/
MIT License
239 stars 153 forks source link

bot-example-flask.py not working? #95

Closed hallyn closed 4 years ago

hallyn commented 5 years ago

I request hooks to be send to my server using:

#!/usr/bin/python
from webexteamssdk import WebexTeamsAPI
import sys

api = WebexTeamsAPI()

wh = api.webhooks.create(name = "All messages",
                    targetUrl = "https://MY_HOST:5000/events",
                    resource = "messages",
                    event = "created",
                    filter = None, secret = None)

print(wh)

and then post a message to a test channel using:

#!/usr/bin/python
from webexteamssdk import WebexTeamsAPI
import sys

def usage():
    print "Usage: {0} channel \"message\"".format(sys.argv[0])

if len(sys.argv) != 3:
    usage()
    sys.exit(1)

api = WebexTeamsAPI()

# Find all rooms that have 'webexteamssdk Demo' in their title
all_rooms = api.rooms.list()

i = 0
chanid=-1
channel = sys.argv[1].lower()
for room in all_rooms:
    if room.title.lower() == channel:
        chanid = room.id
        break

if chanid == -1:
    print "Channel not subscribed: {0}".format(sys.argv[1])
    usage()
    sys.exit(1)

# Post a message to the new room, and upload a file

api.messages.create(chanid, text=sys.argv[2])

using the command:

./post.py SergeTest 'hi gang'

The bot-example-flask.py instance on MYHOST does get a message, but complains about bad request syntax, like:

/home/serge/.local/lib/python2.7/site-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
18.221.216.175 - - [04/Nov/2019 20:11:36] code 400, message Bad request syntax ('\x16\x03\x03\x00\xeb\x01\x00\x00\xe7\x03\x03]\xc0\x85\xf81KW\x1e\xf0I\xd5\xed\xeb\x82J\xdcE\xeeK\xc9\x14\xd6\xf3H\xd8\xd9\xa7;IyOz\x00\x00d\xc0$\xc0(\x00=\xc0&\xc0*\x00k\x00j\xc0')
18.221.216.175 - - [04/Nov/2019 20:11:36] "^V^C^C^@<EB>^A^@^@<E7>^C^C]<C0><85><F8>1KW^^<F0>I<D5><ED><EB><82>J<DC>E<EE>K<C9>^T<D6><F3>H<D8>٧;IyOz^@^@d<C0>$<C0>(^@=<C0>&<C0>*^@k^@j<C0>" 400 -
18.217.166.80 - - [04/Nov/2019 20:11:36] code 400, message Bad request syntax ('\x16\x03\x03\x00\xeb\x01\x00\x00\xe7\x03\x03]\xc0\x85\xf8A\x07\xb8j\xa2\xc7N\xc8\xbf\xe5M\x8eIH\x04G/@\xf0\xdc\x91L\xaf')
18.217.166.80 - - [04/Nov/2019 20:11:36] "^V^C^C^@<EB>^A^@^@<E7>^C^C]<C0><85><F8>A^G<B8>j<A2><C7>Nȿ<E5>M<8E>IH^DG/@<F0>L<AF>" 400 -
18.221.216.175 - - [04/Nov/2019 20:11:36] code 400, message Bad HTTP/0.9 request type ('\x16\x03\x03\x00\xeb\x01\x00\x00\xe7\x03\x03]\xc0\x85\xf8')
18.221.216.175 - - [04/Nov/2019 20:11:36] "^V^C^C^@<EB>^A^@^@<E7>^C^C]<C0><85><F8>^M<BE><BF><F8><FE><B4><C2>zqrW<81>p.
^Vy^X<F8>e<87><A8><C4>t<BD><ED>`<B1><B7>^@^@d<C0>$<C0>(^@=<C0>&<C0>*^@k^@j<C0>" 400 -
18.217.166.80 - - [04/Nov/2019 20:11:36] "POST / HTTP/1.1" 404 -
18.221.216.175 - - [04/Nov/2019 20:11:36] code 400, message Bad request syntax ("\x16\x03\x03\x00\xeb\x01\x00\x00\xe7\x03\x03]\xc0\x85\xf8\x98\xe0\xa0\x19a\x05;\xcdQ\xc5*X\xa2\xe8\xbf\x8dp\xa3\xd1\xce'\x14\xe8\xc0f\xd4@Q\x00\x00d\xc0$\xc0(\x00=\xc0&\xc0*\x00k\x00j\xc0")
18.221.216.175 - - [04/Nov/2019 20:11:36] "^V^C^C^@<EB>^A^@^@<E7>^C^C]<C0><85><F8><98><E0><A0>^Ya^E;<CD>Q<C5>*X<A2>迍p
<A3><D1><CE>'^T<E8><C0>f<D4>@Q^@^@d<C0>$<C0>(^@=<C0>&<C0>*^@k^@j<C0>" 400 -

(109 lines of output, not all pasted above)

hallyn commented 5 years ago

Ping?

It would be a tremendous help to both myself and my team if we could get this working.

hallyn commented 5 years ago

Hm, maybe this project is out of date? Maybe there's a newer python or golang teams api framework i should be using?

cmlccie commented 4 years ago

@hallyn I do apologize that you did not receive a timely response. This is a community-developed and maintained project, and at first glance, it looked like your issue was something local to your setup.

I have confirmed the bot-example-flask.py example code is working as expected. I was unable to reproduce your issue using the code samples you provided (thank you for those!).

You have probably long moved past working on this, but perchance you are still curious:

hallyn commented 4 years ago

Thanks, this would indeed still be useful to me. I'll aim to re-try and verify whether i was using UTF-8 and python3. If python2 is known to not work, that could well be it.

cmlccie commented 4 years ago

Great. Let me know if you run into any issues. For your reference, here is a GIST with the files I used in attempting to recreate your issue. I hope it helps.