sakshi singhal
sakshi singhal

Reputation: 111

How to get json from <class 'requests.models.Response'>

url = cmsServiceBaseUrl
resp = requests.get(url,json=cmsServiceRequestBaseFormat)
return resp.get("data")

The resp type is <class 'requests.models.Response'> but I want json

Upvotes: 2

Views: 3098

Answers (2)

at54321
at54321

Reputation: 11866

You need to call resp.json().

The response will be a JSON parsed into a dictionary or a list of dictionaries.

Here is an example from the docs:

>>> import requests

>>> r = requests.get('https://api.github.com/events')
>>> r.json()
[{'repository': {'open_issues': 0, 'url': 'https://github.com/...

Upvotes: 1

Park
Park

Reputation: 384

You can get a json from the response like this

url=cmsServiceBaseUrl
resp=requests.get(url,json=cmsServiceRequestBaseFormat)
return resp.json()

Here is the related doc from requests: https://docs.python-requests.org/en/master/user/quickstart/#json-response-content

Upvotes: 0

Related Questions