Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise a more relevant error when getting a JSONDecodeError for some reasons #718

Closed
4 of 9 tasks
jeffbuswell opened this issue Jun 5, 2020 · 2 comments · Fixed by #751
Closed
4 of 9 tasks

Raise a more relevant error when getting a JSONDecodeError for some reasons #718

jeffbuswell opened this issue Jun 5, 2020 · 2 comments · Fixed by #751

Comments

@jeffbuswell
Copy link

jeffbuswell commented Jun 5, 2020

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

  • slackclient version: 2.6.2
  • python version: 3.7
  • OS version(s): Linux, Mac OSX

Steps to reproduce:

  1. Make a call to a Slack python endpoint
  2. Occasionally receive a JSONDecodeError

Expected result:

Expect a SlackApiError instead of JSONDecodeError

Actual result:

File "/venv/lib/python3.7/site-packages/slack/web/client.py" line 1710 in team_info
File "/venv/lib/python3.7/site-packages/slack/web/base_client.py" line 200 in api_call
File "/venv/lib/python3.7/site-packages/slack/web/base_client.py" line 333 in _sync_send
File "/venv/lib/python3.7/site-packages/slack/web/base_client.py" line 437 in _urllib_api_call
    `response_body_data: dict = json.loads(response["body"])`
File "/usr/local/lib/python3.7/json/\_\_init\_\_.py" line 348 in loads
File "/usr/local/lib/python3.7/json/decoder.py" line 337 in decode
File "/usr/local/lib/python3.7/json/decoder.py" line 355 in raw_decode
    `raise JSONDecodeError("Expecting value", s, err.value) from None`

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Response from server:

"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /api/team.info was not found on this server.</p>\n</body></html>\n"
@jeffbuswell jeffbuswell changed the title JSONDecodeError in TeamInfo endpoint Occasional JSONDecodeError Jun 5, 2020
@seratch
Copy link
Member

seratch commented Jun 5, 2020

@jeffbuswell Thanks for taking the time to report this.

I tried to reproduce this issue by calling team_info 50+ times on my end (macOS + slackclient 2.6.2) but I was not able to see the same situation.

Regarding the occasional errors with such an unexpected HTML response, how often did you face the issue?

Also, just in case, could you try adding the following lines of code at the beginning of your code? Enabling debug logs may provide some useful information for you.

import logging
logging.basicConfig(level=logging.DEBUG)

In any case, I agree we can improve this SDK to be more consistent even for the cases having such an unexpected response body.

@seratch seratch added this to the 2.8.0 milestone Jun 5, 2020
@seratch seratch changed the title Occasional JSONDecodeError Raise a more relevant error when getting a JSONDecodeError for some reasons Jun 9, 2020
@jeffbuswell
Copy link
Author

This seems to happen with all endpoints, not just teams, and only very occasionally. Probably a bug with the actual slack api itself, not the python client, but would be nice if the client handled it gracefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants