1

I'm trying to pull data from a website. I'm using Python request:

users = requests.get('website name here', headers=headers).json()

I'm getting this error:

raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I know that the data i'm pulling is JSON, which is one of the issues that other people were getting with this error message. My guess is, because there's a username and password required to access the site, it's giving me this error. Could that be it? If so, how can i fix that? I don't want to include my login information in my Python program.

Edit: I now know that authorization was not the issue because i created an authorization token and i'm still getting the same issue.

2
  • 4
    I know that the data i'm pulling is JSON I'm confused what you mean by this. Do you mean that it actually is JSON, or do you mean that it should be JSON, assuming everything worked as expected? Commented Sep 25, 2019 at 19:06
  • 2
    Check the value of .text instead of .json(). It almost certainly isn’t valid json. If the site requires login, then you have to pass the username and password to your program somehow (unless the site offers an alternative method of authentication e.g. oauth). Commented Sep 25, 2019 at 19:07

1 Answer 1

2

request.get() returns response (Doc) object and response.content will have actual response.

I would suggest trying:

import json
import requests

headers = {...}
response = requests.get('website name here', headers=headers)

try:
    users = json.loads(response.content)
except Exception as ex:
    print("Error getting response")
Sign up to request clarification or add additional context in comments.

1 Comment

May be the response is not a valid json then. Try fetching the URL from browser/postman and validate the response on jsonformatter.curiousconcept.com. It should help you understand what is wrong. Happy learning!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.