Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I dont get why I cant get a json format with requests.Request()?

from requests import Request as R

markets = R("GET", "https://ftx.com/api/markets")
print(markets.json())

Error:
print(markets.json())
TypeError: ‘NoneType’ object is not callable

Process finished with exit code 1

I want to get the HTTP response as json but it doesnt work although it works with requests.get().
Help please?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Request is just the object that represents the request. You want requests.request to construct and make the request.

import requests

markets = requests.request("GET", "https://ftx.com/api/markets")

The json attribute of a Request object would be the JSON payload of the request, not the JSON response.

To make a request manually with a Request object, you need to first prepare it, then use a session to send the request. For example,

markets = requests.Request("GET", "https://ftx.com/api/markets")
r = markets.prepare()
s = requests.Session()
result = s.send(r)
print(result.json())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading