python - ServiceNow REST API 集成:无法解码 JSON 对象
问题描述
我尝试使用 python 脚本对 serviceNow 记录进行一些集成,并参考此链接中给出的示例以使用 Http Request Patch 方法更新记录:Table API Python
这是我的代码:
#Need to install requests package for python
#sudo easy_install requests
import requests
# Set the request parameters
url = 'https://instance.owndomain.com/api/now/table/sc_req_item/2a2851fe88709010b9120e9b506dd9a9'
user = 'username'
pwd = 'password'
# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}
# Do the HTTP request
response = requests.patch(url, auth=(user, pwd), headers=headers ,data='{"u_switch_status_automation":"In Processing using Python", "u_switch_description":"The Automation currently processing this SR using Python"}')
# Check for HTTP codes other than 200
if response.status_code != 200:
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
exit()
# Decode the JSON response into a dictionary and use the data
print('Status:',response.status_code,'Headers:',response.headers,'Response:',response.json())
我得到的结果如下:
/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made to host 'instance.owndomain.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
Traceback (most recent call last):
File "/home/automation/switchConf/updateRecord.py", line 18, in <module>
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
File "/usr/lib/python2.7/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
解决方案
推荐阅读
- c - 需要帮助从 .csv 文件 C 中解析数据
- php - 尝试使用 SQL 在 PHP 中获取两个日期之间的日期
- javascript - 使用 Javascript 和节点 csv-parse 将 csv 文件解析为数组
- swiftui - 如何避免与 SwiftUI 中的嵌套结构的命名冲突?
- highcharts - 具有多个系列的 highcharts 的可访问性
- java - 如何在 Java 中使用返回 zip 文件的 REST API?
- functional-programming - OCaml 输入类型
- android - 如何在长段落中搜索文本并自动滚动以在颤动中找到文本?
- android - 如何在 Flutter 中使用带有 dart 代码的 play store 按需功能模块?
- r - r中的嵌套lappy