HI
I am writing some code to use rest API calls to our Service Desk Solution and get information from tickets.
I am using the request module to use the requests.post and requests.get commands.
The code must login, get info and logout
The login and logout calls works ok, the status code always is 200. The API call to get the ticket information returns a 500 code.
reviewing the requests properties i print the url code used in the requests.get call, and I note the request.url missformat the string
I mean, the original url string is:
url = 'http://<ip_server>//cgrestapi/api/entity/incidentrequest/TodosLosIncidentes??filter=[ID]=99'
this string is used in this call
r = req.get(url)
the I print the status code and url (print (r.status_code) & print (r.url) ), the r.url get this string:
http://<ip_server>//cgrestapi/api/entity/incidentrequest/TodosLosIncidentes??filter=%5BID%5D=99
As you note the url string have %5B and %5D, instead of "[" and "]"
Some one have some idea why the string changes in the GET call?
This is the code and the output result (the yellow code is the code with the problem):
I am writing some code to use rest API calls to our Service Desk Solution and get information from tickets.
I am using the request module to use the requests.post and requests.get commands.
The code must login, get info and logout
The login and logout calls works ok, the status code always is 200. The API call to get the ticket information returns a 500 code.
reviewing the requests properties i print the url code used in the requests.get call, and I note the request.url missformat the string
I mean, the original url string is:
url = 'http://<ip_server>//cgrestapi/api/entity/incidentrequest/TodosLosIncidentes??filter=[ID]=99'
this string is used in this call
r = req.get(url)
the I print the status code and url (print (r.status_code) & print (r.url) ), the r.url get this string:
http://<ip_server>//cgrestapi/api/entity/incidentrequest/TodosLosIncidentes??filter=%5BID%5D=99
As you note the url string have %5B and %5D, instead of "[" and "]"
Some one have some idea why the string changes in the GET call?
This is the code and the output result (the yellow code is the code with the problem):
import requests as req from requests.auth import HTTPBasicAuth jbody={"username":"LumaServiceAccount","password":"admin" } r = req.post( "http://<ip_server>/cgrestapi/api/authenticate/user", json=jbody ) print('URL Login: ', r.url) datos = r.json() print ("Staus re.post-login: ", r.status_code ) id = datos["sessionId"] print ('Ticket get info') [color=#F1C40F]url = 'http://<ip_server>//cgrestapi/api/entity/incidentrequest/TodosLosIncidentes??filter=[ID]=99' r = req.get(url) print('URL r.get: ', r.url) print ("Staus re.get: ", r.status_code) [/color] print('logout') Headers={"sessionid":id} r = req.post( 'http://172.16.10.30/cgrestapi/api/user/logout', headers=Headers ) print ("Staus re.post -logou: ", r.status_code ) Output: PS C:\Software\Programs> py testr.py URL Login: http://<ip_server>/cgrestapi/api/authenticate/user Staus re.post-login: 200 Ticket get info URL r.get: http://<ip_server>/cgrestapi/api/entity/incidentrequest/TodosLosIncidentes??filter=%5BID%5D=99 Staus re.get: 500 logout Staus re.post -logou: 200
Larz60+ write Jul-05-2022, 06:54 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.