Unable to Create Change using API in Python using Request module put method

sam149
Kilo Explorer

Hi Everyone i was trying to create a change using the Servicenow API but I'm getting the following error.


My Code :-

import requests

url="https://******.service-now.com/api/now/table/change_request"

user="***"
password="*****"

headers={"Content-Type":"application/json","Accept":"application/json"}


response = requests.put(url, auth=(user, password), headers=headers ,data="<request><entry><assignment_group>testgroup</assignment_group><category>prod</category><requested_by>user1</requested_by><type>comprehensive</type></entry></request>")
print(response.status_code)
#print(response.json())

 

The Error which I'm getting:-

Traceback (most recent call last):
File "****\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "******\Python\Python36-32\lib\site-packages\urllib3\util\connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "*******\Python\Python36-32\lib\socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed


When i'm executing request with **get** it's working fine printing the status code of 200 but when i use with **.put** and **data** it's throwing error.

response=requests.get(url,auth=(user,password),headers=headers)

Can you please help me...

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Try using POST. I tried below and it works.

 

POST https://XXX.service-now.com/api/now/table/change_request


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Try using POST. I tried below and it works.

 

POST https://XXX.service-now.com/api/now/table/change_request


Please mark this response as correct or helpful if it assisted you with your question.

SanjivMeher
Kilo Patron
Kilo Patron

Also FYI, put is only used for updating existing records


Please mark this response as correct or helpful if it assisted you with your question.

sam149
Kilo Explorer

Hi Sanjiv,

Thanks for Helping I'll Try and will let you know by tonight as I am at work and there is no environment for testing here.

 

 

 

 

 

 

sam149
Kilo Explorer

Hi Sanjiv,

 

I checked with post

response = requests.post(url, auth=(user, password), headers=headers ,data="<request><entry><assignment_group>testgroup</assignment_group><category>prod</category><requested_by>user1</requested_by><type>comprehensive</type></entry></request>")
 
but it's showing error 400 bad request
 
and also I'm using Jakarta instance is that the issue.