From `Expecting value: line 1 column 1 (char 0)` to `Response content not in json format`

Hi!
Please run 
```
import requests

r = requests.get('http://httpbin.org/status/200')
r.status_code
r.json()
```
The answer is:
```
200
JSONDecodeError:  Expecting value: line 1 column 1 (char 0)
```
I do not think it is informative and maybe it could contain something like:
`Json: Response content is not in the json format`

Do you think it is a good idea to wrap line 892 of requests/models.py into something like:

```
try: 
    return complexjson.loads(self.text, **kwargs)  # current line 892
except JSONDecodeError:
    print('Response content is not in the json format')
```
?

## System Information
```
(py3)  ~/ $ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.6"
  },
  "platform": {
    "release": "4.15.0-39-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "1010007f"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": false
}
```


If you inspect the response headers, it's not returning JSON so you shouldn't be unconditionally calling `.json()` on the response.

Thanks for the quick reply!
You solved my problem!

For future reference, below how to get the JSON content or to get some spam:
```
import requests


url = 'http://httpbin.org/status/200'
r = requests.get(url)

if 'json' in r.headers.get('Content-Type'):
    js = r.json()
else:
    print('Response content is not in JSON format.')
    js = 'spam'
```

> Thanks for the quick reply!
> You solved my problem!
> 
> For future reference, below how to get the JSON content or to get some spam:
> 
> ```
> import requests
> 
> 
> url = 'http://httpbin.org/status/200'
> r = requests.get(url)
> 
> if 'json' in r.headers.get('Content-Type'):
>     js = r.json()
> else:
>     print('Response content is not in JSON format.')
>     js = 'spam'
> ```

unfortunately not all systems that return json set the Content-Type correctly

The best way to handle this is catch the JSONDecodeError:
```python
r = requests.get(url)
try:
    data = r.json()
except ValueError:
    print("Response content is not valid JSON")
```

**p.s.** `JSONDecodeError:  Expecting value: line 1 column 1 (char 0)` specifically happens with an empty string (i.e. empty response content)




@wesinator 
> **p.s.** `JSONDecodeError: Expecting value: line 1 column 1 (char 0)` specifically happens with an empty string (i.e. empty response content)

Not specifically. As the name suggests, it's a decoding error:
```
>>> import json
>>> json.loads('<html>')
Traceback (most recent call last):
  ...
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
```

To check whether it's an empty response you can look at the exception's `doc` attribute:
```
try:
    json.loads(content)
except json.decoder.JSONDecodeError as e:
    if not e.doc:
        raise ValueError('Empty response.')
    else:
        raise ValueError(f"Decoding error at char {e.pos} (line {e.lineno}, col {e.colno}): '{e.doc}'")
```

I know, I meant that the specific position `line 1 column 1 (char 0)` happens in the case there is an empty string 

Not necessarily. In my previous comment there is an example of the opposite.

The `line x column y (char z)` only shows where the invalid starting value for an expected object was found or, if it's the case, not found.

```
>>> json.loads('{"key":')
Traceback (most recent call last):
  ...
json.decoder.JSONDecodeError: Expecting value: line 1 column 8 (char 7)
```

In addition to empty responses, the `line 1 column 1 (char 0)` also often means that the document is in another format (such as XML or HTML, as in my first comment).

That's why I believe the op's request would clearly be useful. That's a significant difference.

```
import requests

def methodPost(_url, _data, _headers):
    a = 0
    while a != 1:

        data = requests.post(_url, data=_data, headers=_headers)

        if 'json' in data.headers.get('Content-Type'):
            js = data.json()
            a = 1
        else:
            print('Response content is not in JSON format.')
            js = 'spam'
            a = 0

    return js
```



.....
`            r = methodPost(url, '{"data": "123"}', {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'})`

I am trying to read a json file which consist of squad dataset for question answering .
It is showing the same error ,I have the dataset in the local .


![Screenshot 2021-06-16 194220](https://user-images.githubusercontent.com/40178834/122236057-d284a480-cedb-11eb-9c93-162863715976.png)


All Possible Working solution added [[Solved] JSONDecodeError: Expecting value: line 1 column 1 (char 0)](https://flutterq.com/jsondecodeerror-expecting-value-line-1-column-1-char-0/)


import requests
import json
import sys
encoding = sys.stdout.reconfigure(encoding='utf-8')
HEADERS = {'user-agent': ('Mozilla/5.0 (Windows NT 10.0; Win64; x64)' 'AppleWebKit/537.36 (KHTML, like Gecko)' 'Chrome/92.0.4515.159 Safari/537.36'), 'referer': 'https://www.myntra.com/men-clothing?p=2&plaEnabled=false'}
url = "https://www.myntra.com/gateway/v2/search/men-clothing-?p=1&plaEnabled=false&rows=50&o=0?apiKey:AIzaSyDAegtWIjzK09VsL5KH05nn-zzCSSql3H4"
ur = "https://www.myntra.com/men-clothing?p=2&plaEnabled=false"
response = requests.get(url, headers=HEADERS).json()
resp = response.text
data = json.loads(resp)

error:-json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)