aio-libs / aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
https://docs.aiohttp.org
Other
15.18k stars 2.02k forks source link

slack_bot / slack_sdk errors since 3.11.x #9966

Closed jasonwbarnett closed 1 week ago

jasonwbarnett commented 1 week ago

Describe the bug

After upgrading from 3.10.x to 3.11.x when starting a simple slack bolt app, an exception is raised.

To Reproduce

  1. Create socket_mode_async.py from this source.

  2. pip install "aiohttp>=3.11.2"

  3. export vars

    export SLACK_APP_TOKEN=xapp-***
    export SLACK_BOT_TOKEN=xoxb-***
  4. Run app

    python ./socket_mode_async.py

Expected behavior

I would expect any changes from 3.10 to 3.11 to not break callers and for this to work just like it did in 3.10.x.

Logs/tracebacks

INFO:slack_bolt.AsyncApp:The old session (s_277760337) has been abandoned
INFO:slack_bolt.AsyncApp:A new session (s_277760389) has been established
DEBUG:slack_bolt.AsyncApp:Sending a ping message with the newly established connection (s_277760389)...
ERROR:slack_bolt.AsyncApp:Failed to connect (error: string argument without an encoding); Retrying...
Traceback (most recent call last):
  File "/Users/user/.cache/pants/named_caches/pex_root/venvs/0/8c8e6c1c955720eab9ea7950faab06550bff5a40/575ca5ce34ac5d283b0502f9efc6408236868ea9/lib/python3.11/site-packages/slack_sdk/socket_mode/aiohttp/__init__.py", line 390, in connect
    await self.current_session.ping(f"sdk-ping-pong:{t}")
  File "/Users/user/.cache/pants/named_caches/pex_root/venvs/0/8c8e6c1c955720eab9ea7950faab06550bff5a40/575ca5ce34ac5d283b0502f9efc6408236868ea9/lib/python3.11/site-packages/aiohttp/client_ws.py", line 229, in ping
    await self._writer.send_frame(message, WSMsgType.PING)
  File "/Users/user/.cache/pants/named_caches/pex_root/venvs/0/8c8e6c1c955720eab9ea7950faab06550bff5a40/575ca5ce34ac5d283b0502f9efc6408236868ea9/lib/python3.11/site-packages/aiohttp/_websocket/writer.py", line 136, in send_frame
    message = bytearray(message)
              ^^^^^^^^^^^^^^^^^^
TypeError: string argument without an encoding

Python Version

$ python --version
3.11

aiohttp Version

$ python -m pip show aiohttp
3.11.2

multidict Version

$ python -m pip show multidict
6.1.0

propcache Version

$ python -m pip show propcache
0.2.0

yarl Version

$ python -m pip show yarl
1.17.2

OS

Ubuntu 22.04

Related component

Client

Additional context

No response

Code of Conduct

bdraco commented 1 week ago

ping's message is typed to be bytes https://github.com/aio-libs/aiohttp/blob/be31bed20210b6d7380aed8702a17994ea6a2d59/aiohttp/client_ws.py#L229

Change

await self.current_session.ping(f"sdk-ping-pong:{t}")

to

await self.current_session.ping(f"sdk-ping-pong:{t}".encode("utf-8"))
bdraco commented 1 week ago

Looks like it was always typed that way on 3.10 as well https://github.com/aio-libs/aiohttp/blob/f5d5da43b05af7f62a40dff8a87e9c1a9bd479a2/aiohttp/client_ws.py#L217

bdraco commented 1 week ago

https://github.com/slackapi/python-slack-sdk/blob/6bcf7eccd0e4750f74ca8c3fd73139da2b6190b8/slack_sdk/socket_mode/aiohttp/__init__.py#L175

https://github.com/slackapi/python-slack-sdk/blob/6bcf7eccd0e4750f74ca8c3fd73139da2b6190b8/slack_sdk/socket_mode/aiohttp/__init__.py#L390

Looks like its a bug in the slack_sdk that was relying on the writer auto converting it internally which doesn't happen anymore in 3.11

bdraco commented 1 week ago

https://github.com/slackapi/python-slack-sdk/issues/1592

jasonwbarnett commented 1 week ago

Gotcha. Just seemed like a break in contract, but I guess what you're saying is that this caller was broken the whole time. I'll post a PR shortly to https://github.com/slackapi/python-slack-sdk

Thanks

bdraco commented 1 week ago

I guess what you're saying is that this caller was broken the whole time.

Yup, It was a bit of luck that it worked before.

bdraco commented 1 week ago

Closing this since the fix needs to happen in https://github.com/slackapi/python-slack-sdk/issues/1592