Majs
Majs

Reputation: 66

API call returns full response in Postman but only first instance of json object using requests

I am making a simple GET request, when these requests are made through postman I get the full response. However, when making the same requests via Python using requests lib I only get a single instance of object "user". The exact same code works jsut as expected when going to one of their other endpoints.

Postman result:

{
  "user": {
    //...
  },
  "user": {
    //...
  },
  //...
}

Python response.json():

{
  "user": {
     //...
  }
}

Code:

url = 'my_url'
auth = ('user', 'pass')

response = requests.get(url, auth=auth)
return response

I have walked through the response and URL is exact same as when I get the full response from Postman. Not sure what Im missing?

Upvotes: 0

Views: 754

Answers (1)

Daniel Geffen
Daniel Geffen

Reputation: 1862

This is because you have two identical "user" keys in the returned object. Postman shows you the raw data returned, but when you call response.json() it parses the data and converts it to a python dictionary, which cannot have two identical keys in an object (same for JSON by the way).

Upvotes: 0

Related Questions