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?
>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())