添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
强悍的创口贴  ·  使用 Java 管理 Blob ...·  1 周前    · 
耍酷的啄木鸟  ·  Imports - Post Import ...·  1 周前    · 
睿智的柠檬  ·  为什么这个vuejs ...·  6 月前    · 
火星上的猴子  ·  deeplearn-api/deeplear ...·  6 月前    · 
含蓄的镜子  ·  comic-downloader · ...·  8 月前    · 
高大的木瓜  ·  常见问题 – ...·  8 月前    · 

Hi, I tried do some integration towards serviceNow using python script and referring example given in this link to update the records: Table API Python example

Here is my code:

#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())

And the result I got is as follows:

/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made to host 'oneservice.ssoe.moe.edu.sg'. 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

It work fine when I tested it on my own dev instance, however, it returned like this when I used the script towards my company own domain instance.

your endpoint is incorrect

please remove the dot character; it should be below

url = 'https://instance.owndomain.com/api/now/table/sc_req_item/2a2851fe88709010b9120e9b506dd9a9'

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

which http method you are using?

Also are those valid fields which you are using in json?

Regards
Ankur

Adding an objectClass (contact) to an AD Group using MS adv2 integration in Developer forum Slack inbound error debugging in Developer forum Datastream Pagination for XML in Developer forum