首页 > 解决方案 > Why I'm getting two different outputs?

问题描述

I'm trying to access IBM Maximo by REST. I was able to do it with Postman by doing a GET request to check if the a particular incident exists: Postman image. Now I want to do it in Python but I can't have the same output:

params = {
    'oslc.select':'*', 
    'oslc.where':'ticketid="IN43550232"',
    }

r = requests.get(url,params=params)

When I print(r.text) the output is the html of a page and when I print(r.json()) I get:

File "C:\Users\User.spyder-py3\Projects\GET.py", line 27, in print(r.json())

File "C:\Users\User\anaconda3\lib\site-packages\requests\models.py", line 897, in json return complexjson.loads(self.text, **kwargs)

File "C:\Users\User\anaconda3\lib\json_init_.py", line 348, in loads return _default_decoder.decode(s)

File "C:\Users\User\anaconda3\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end())

File "C:\Users\User\anaconda3\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value

From what I understant the output is not in a json format... My question is, how can I solve this problem? Thank you

SOLUTION:

headers = {
    'Cookie':'...',
    'Accept':'*/*',
    'Accept-Encoding':'gzip, deflate, br',
    'Connection':'keep-alive',
    }
params = {
    'oslc.select':'*', 
    'oslc.where':'ticketid="IN43550232"',
    }

r = requests.get(url, headers=headers, params=params)
r.encoding = 'utf-8'
print(r.json())

标签: pythonjsonrestpython-requestspostman

解决方案


Try removing the quotes. Like this:

r = requests.get(url, headers=headers, params=params, verify=False)

推荐阅读