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

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

Brian Destura
  • 11,487
  • 3
  • 18
  • 34
sakshi singhal
  • 101
  • 2
  • 9
  • 1
    requests library has json method. Just use resp.json() – Park Jul 26 '21 at 04:23
  • Does this answer your question? [HTTP requests and JSON parsing in Python](https://stackoverflow.com/questions/6386308/http-requests-and-json-parsing-in-python) – Albin Paul Jul 26 '21 at 04:30

2 Answers2

1

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/...
at54321
  • 8,726
  • 26
  • 46
0

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

Park
  • 364
  • 3
  • 14