python - 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())
解决方案
Try removing the quotes. Like this:
r = requests.get(url, headers=headers, params=params, verify=False)
推荐阅读
- ios - 如何快速找到 QuadCurve 和 Line UIBezierPaths 之间的交点(CGPoint)?
- javascript - 滚动到顶部后停止向下滚动
- apache-kafka - Kafka 消费者组 - 分区数 - 复制数
- systemc - 从 SC_THREAD 进程调用 sc_fifo::nb_write() 是否安全?
- vb.net - 关于简单除法和乘法的 VB 算术溢出
- java - 将 XML 位图数据转换为图像
- vuejs2 - 关注 Vuex 商店中的 URL 查询参数
- r - R 1 列带条形图,其他 3 列作为同一图表上的线
- jquery - 什么是正确的 jquery 选择器语法?
- java - 为什么即使实现了 Iterable,我也会收到 foreach 编译器错误?