This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not getting any output using python, but using Postman i am getting the output

Calling a Dell one web service,

Using POSTMAN, first i used POST to get the session ID, second GET to get the output response.

In POSTMAN,

1) POST:

import requests
url = "">192.168.**.*/.../apphost"
payload = "{\"authString\":\"Module=DialogUser;User=admin;Password=Abcd1234\"}"
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache",
    'postman-token': "469a3d55-83f3-b1ee-a4**-1d1084d47***"
    }
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)

OUTPUT:

{
    "sessionId": "0b**88zeO8h81TZ2z***",
    "displayName": "",
    "responseStatus": {}
}

2) GET:

import requests
url = "">192.168.**.*:80/.../TableName"
querystring = {"loadType":"Default"}
payload = "{\"authString\":\"Module=DialogUser;User=admin;Password=Abcd1234\"}"
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache",
    'postman-token': "fccfab**-02**-17**-ffeb-725f3b244***"
    }
response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
print(response.text)


OUTPUT:

[{"uri":"http://192.168.**.*/IMAppServer/api/entity/TableName/c6df1***-b51b-4f70-bd87-c64f60b4****","display":"SENSOR","longDisplay":"SENSOR","values":{"DisplayName":"SENSOR","UID_TableName":"c6df1***-b51b-4f70-bd87-c64f60b44***","Deletion":0},"displayValues":{"Deletion":""}}]
 

So I am able to retrieve values using POSTMAN.

But the same thing when i do it in Python3 The first POST request is giving me the output(i.e Session_id),

but the second query is not giving me anything. Only status code: 401

Any help?

  • You need to maintain the session.  Here is an example using the requests library:

    #Use the requests library
    import requests

    #Base things
    baseUrl = "">https://myserver/AppServer"
    #you shoul replace with your own authorization string
    authString = "Module=DialogUser;User=viadmin;Password="
    authBody = {'authString':authString}

    #set up headers
    headers = {'Accept':'application/json'}

    #set up a session to keep auth cookies
    session = requests.Session()
    session.headers.update(headers)

    #Authenticate
    authUrl = baseUrl + '/auth/apphost'
    authReq = session.post(authUrl, json=authBody, verify=False)

    #Query for all persons
    personUrl = baseUrl + '/api/entities/person'
    personReq = session.post(personUrl, verify=False)

    print(personReq)