line-bot-sdk-python icon indicating copy to clipboard operation
line-bot-sdk-python copied to clipboard

async api error catch

Open m124578n opened this issue 1 year ago • 0 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.

m124578n avatar Oct 17 '24 06:10 m124578n