0

I am just trying to access an API through Postman and its wokring fine.The Postman header response is returning some details like below

Authentication-Token →/DwG7gAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Connection →keep-alive
Content-Length →16
Content-Type →application/json;charset=UTF-8
Date →Tue, 25 Sep 2018 17:44:01 GMT
Server →Apache-Coyote/1.1 

But when I am trying to do same in Python I am just receivig the response status.(200)

How can I get the above Authentication-Token etc details like Postman in python code.

import requests
import json

url = 'https://test-orchestrator.lmig.com/baocdp/rest/login/'
headers = {"Content-Type": "application/json"}
data1 = {"username":"abc", "password":"abc"}
print("Testing authentication for Remedy test environment...")
change_response=requests.post(url,data=json.dumps(data1),headers=headers)
print(change_response)
Chinmay Nayak
  • 203
  • 5
  • 17
  • 1
    Possible duplicate of [How can I see the entire HTTP request that's being sent by my Python application?](https://stackoverflow.com/questions/10588644/how-can-i-see-the-entire-http-request-thats-being-sent-by-my-python-application) – HunterM267 Sep 25 '18 at 18:08
  • What do you get if you use print(change_response.text) or print(change_response.headers)? – Kyhle Ohlinger Sep 25 '18 at 18:12

1 Answers1

1

If you print change_response, it will most likely look like this <status [200]> or something to that effect. If you want to see the contents of the response, you can use the vars response.text, response.content, or response.headers (among others) or since this is a json response, you can use the method response.json() to convert the contents of the response into a dictionary full of native Python data types.

I would reccommend x = response.json(), as the contents of your response seem to contain an auth token that you will most likely need to communicate with this device further. You can then use auth+token = x[token_key] to isolate that token.

bcstryker
  • 456
  • 3
  • 15
  • response.headers giving zero content length {'Content-Length': '0', 'Connection': 'keep-alive'} – Chinmay Nayak Sep 25 '18 at 19:16
  • Something must be wrong with your call. I cannot access the url you listed here so without you showing me the full output of the code when you try to run it, I don't know how much I can do to help you. – bcstryker Sep 25 '18 at 21:38
  • Actually "response.headers" worked.I have restarted my VS code editor and rerun the python code.It then worked. – Chinmay Nayak Sep 26 '18 at 09:20