Skip to content

Socket Mode: Failed to connect (error: string argument without an encoding) w/ Azure App Service + aiohttp 3.11.2 #1202

@jeremybeeman

Description

@jeremybeeman

Reproducible in:

The slack_bolt version

slack_bolt==1.21.2

Python runtime version

Python 3.12.2

OS info

Trying to run from an Azure App Service that is VNET integrated. All outbound connectivity is required to go via proxy.

OS version: Unix 5.15.164.1
64 bit system: True
64 bit process: True
Processor count: 1
Machine name: 2f7e55a2dc74
Instance id: 0e5af111c5b338ee855cdd761d032f2c022705d7e379fdcddb5270f11cfa1b68
Short instance id: 0e5af1
CLR version: 6.0.35
System directory:
Current working directory: /opt/Kudu
IIS command line: /opt/Kudu/Kudu.Services.Web.dll

(antenv) root@app-service:/home/site/wwwroot# cat /etc/os-release

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"

NAME="Debian GNU/Linux"

VERSION_ID="11"

VERSION="11 (bullseye)"

VERSION_CODENAME=bullseye

ID=debian

HOME_URL=https://www.debian.org/

SUPPORT_URL=https://www.debian.org/support

BUG_REPORT_URL=https://bugs.debian.org/

(antenv) root@e9813d4e8a9f:/home/site/wwwroot# uname -r

5.15.164.1-1.cm2

Steps to reproduce:

Slack Bolt Socket Mode Snippet
proxy_url = os.getenv('PROXY_URL')

client = AsyncWebClient(

    token = os.getenv('SLACK_BOT_TOKEN'),

    proxy = proxy_url

)

app = AsyncApp(client = client)
handler = AsyncSocketModeHandler(

        app, os.getenv('SLACK_APP_TOKEN'),

        proxy = proxy_url
    )

handler_task = asyncio.create_task(handler.start_async())

The code snippet is used alongside a separate FastAPI instantiation and calls to a separate aiohttp Web Client.

Build and deploy the slack bolt code using the github actions deployment shown here: https://github.com/Azure/actions-workflow-samples/blob/master/AppService/python-webapp-on-azure.yml

Expected result:

To be able to create a socket connection between Slack and the app service.

Actual result:

The initial call to slack is made, and then the code then fails with a string encoding error with aiohttp (put XXXXX for some IDs).

2024-11-17T01:37:30.923152692Z Received the following response - status: 200, headers: 
{'Date': 'Sun, 17 Nov 2024 01:37:30 GMT', 'Server': 'Apache', 'Vary': 'Accept-Encoding', 'x-slack-req-id': 'XXXXX', 'x-content-type-options': 'nosniff', 'x-xss-protection': '0', 'x-robots-tag': 'noindex,nofollow', 'Pragma': 'no-cache', 'Cache-Control': 'private, no-cache, no-store, must-revalidate', 'Expires': 'Sat, 26 Jul 1997 05:00:00 GMT', 'Content-Type': 'application/json; charset=utf-8', 'x-accepted-oauth-scopes': 'connections:write', 'x-oauth-scopes': 'connections:write', 'Access-Control-Expose-Headers': 'x-slack-req-id, retry-after', 'Access-Control-Allow-Headers': 'slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'referrer-policy': 'no-referrer', 'x-slack-unique-id': 'XXXXX', 'x-slack-backend': 'r', 'Access-Control-Allow-Origin': '*', 'Via': '1.1 [slack-prod.tinyspeck.com](http://slack-prod.tinyspeck.com/), envoy-www-iad-pcrbflcw,envoy-edge-iad-fptlrjqw', 'Content-Encoding': 'gzip', 'Content-Length': '165', 'x-envoy-attempt-count': '1', 'x-envoy-upstream-service-time': '19', 'x-backend': 'main_normal main_canary_with_overflow main_control_with_overflow', 'x-server': 'slack-www-hhvm-main-iad-exxh', 'x-slack-shared-secret-outcome': 'no-match', 'x-edge-backend': 'envoy-www', 'x-geoname-id': 'notfound', 'x-slack-edge-shared-secret-outcome': 'no-match'}, body: {'ok': True, 'url': 'wss://wss-primary.slack.com/link/?ticket=481d5f77-0d56-402e-8472-73c552fefcd4&app_id=XXXXX'} 
2024-11-17T01:37:31.059929384Z INFO: [169.254.129.1:65493](http://169.254.129.1:65493/) - "GET /robots933456.txt HTTP/1.1" 404 Not Found 2024-11-17T01:37:31.070751719Z A new session (s_8500438350666) has been established 
2024-11-17T01:37:31.070787721Z Sending a ping message with the newly established connection (s_8500438350666)... 
2024-11-17T01:37:31.116712841Z Failed to connect (error: string argument without an encoding); Retrying... 
2024-11-17T01:37:31.116745843Z Traceback (most recent call last): 2024-11-17T01:37:31.116752044Z File "/home/site/wwwroot/antenv/lib/python3.12/site-packages/slack_sdk/socket_mode/aiohttp/__init__.py", line 390, in connect 2024-11-17T01:37:31.116757544Z await self.current_session.ping(f"sdk-ping-pong:{t}") 2024-11-17T01:37:31.116762544Z File "/home/site/wwwroot/antenv/lib/python3.12/site-packages/aiohttp/client_ws.py", line 229, in ping 2024-11-17T01:37:31.116767745Z await self._writer.send_frame(message, WSMsgType.PING) 2024-11-17T01:37:31.116772745Z File "/home/site/wwwroot/antenv/lib/python3.12/site-packages/aiohttp/_websocket/writer.py", line 136, in send_frame 2024-11-17T01:37:31.116777745Z message = bytearray(message)

Requirements

slack_bolt==1.21.2

requests==2.32.3

python-dotenv==1.0.1

slack_sdk==3.33.3

aiohttp==3.11.2

uvicorn==0.32.0

fastapi==0.115.5

Metadata

Metadata

Assignees

Labels

area:asyncbugSomething isn't workingdependenciesPull requests that update a dependency file

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions