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

sam149
Kilo Explorer

Hi Sanjiv,

 

The POST method is working fine .

 

Actually the error is in header I have gine there JSON as Request type and was passing XMl that was the issue.

 

Thanks for the help......!