async api error catch
Closed this issue · 3 comments
System Informations
- Python version: 3.10.12
- SDK version: 3.11.0
Expected Behavior
If line api get http status code in 200<= X <300, this should get the LineBotApiError in async_api.py line: 2562
Current Behavior
But it cause, 2024-10-17 14:36:48,548 - root - INFO - error: object method can't be used in 'await' expression
File "/home/azureuser/VHS_short_bk/venv/lib/python3.10/site-packages/linebot/async_api.py", line 2567, in __check_error
error=Error.new_from_json_dict((await response.json)),
TypeError: object method can't be used in 'await' expression
The error cause in async_api.py line 2567,
and I change the line
""" await response.json """
to
""" response.json() """
It got the correct action.
2024-10-17 14:41:49,277 - root - INFO - error: LineBotApiError: status_code=400, request_id=, error_response={"details": [{"message": "cannot contain null elements", "property": "/body/contents"}], "message": "A message (messages[0])\u00a0in the request body is invalid"}, headers={'server': 'legy', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate', 'content-type': 'application/json', 'date': 'Thu, 17 Oct 2024 06:41:49 GMT', 'expires': '0', 'pragma': 'no-cache', 'x-content-type-options': 'nosniff', 'x-frame-options': 'DENY', 'x-line-request-id': , 'x-xss-protection': '1; mode=block', 'content-length': '152'}
I got the error message that I want.
Thank you for using the line-bot-sdk-python.
Is linebot.aiohttp_async_http_client.AiohttpAsyncHttpClient being passed to the initialization of AsyncLineBotApi? linebot.aiohttp_async_http_client.AiohttpAsyncHttpResponse defines a json getter as a @property, so it doesn't cause an error in the above code.
The linebot/async_api.py is a deprecated version and does not support the linebot.v3.messaging.AsyncApiClient introduced in v3.
Thank you for your understanding.
Got it. I didn't notice the deprecated version message.
I'll try to use "Use 'from linebot.v3.messaging import AsyncMessagingApi' and 'AsyncMessagingApi(...).push_message(...)' instead. See https://github.com/line/line-bot-sdk-python/blob/master/README.rst for more details."
Thank you for your reply.