Here is an article that explains why you cannot access data from a URL -API with JSON in Python:
Title: cannot receive any information from Binance API with JSON: A guide to understanding API restrictions and problems
Introduction
As a developer, the information you need is one of the most exciting aspects when working on projects. However, when it comes to APIs like the Binance -API, it can be difficult to understand your limits. In this article we will examine why the calling of data from Binance -API with JSON may not work and provide some problem bypass.
Why can’t I get the information from the URL -API with JSON?
The Binance -API is a relaxing API that offers access to various financial market data, including cryptocurrency prices. If you send a get request to a specific URL with the “Requests” library in Python, you send an HTTP request to the server and receive an answer. The answer contains the requested data, but JSON (JavaScript object notification) is usually not used with relaxing APIs.
The main problem here is that the Binance -API JSON does not use by default. Instead, the data is returned as a simple text in the form of a string. This is because relaxing Apis Json often does not have to support their internal data exchange. Instead, they offer a simple and convenient way to access their resources.
Why doesn’t my URL work with JSON?
If you send a get request to https: // api.binance.com/api/v1/ticker/24 hr
, the server answers with a simple text of the text that contains the ticker list for 24-hour prices. This string is not so formatted that it can easily be analyzed in a Python dictionary or object.
This is how the answer could look:
`Json
[
{
“Symbol”: “BTC/EUR”,
“Lastprice”: “4,0025”,
“High”: “4,0065”,
“Low”: “3,9930”,
“Open”: “4,0011”,
“Close”: “4,0032”
},
{
“Symbol”: “Eth/USD”,
“Lastprice”: “4,0027”
}
]
`
This answer does not contain a JSON object, but a list of dictionaries that contain the requested data.
Problem debits:
If you have to call up data from the Binance -API with JSON, you will find some problem bypass here:
- Use the parameter
jon
: You can specify the parameter” JSON “if you make the Get request:
`Python
Import inquiries
Binance = Requests.Get (" json = true)
This returns a JSON object that contains the ticker list.
- Use the attribute “Data” : You can also access the answer data with the attribute “Data”:
`Python
Import inquiries
Binance = Requests.Get ("
print (binance.json ())
This prints out a JSON object that contains the requested data.
- Use a library such as “Requests-Json-Parser”: There are libraries available that can analyze JSON responses in Python objects, such as: B. “Requests-Json-Parser”:
`Python
Import inquiries
Import parse_json_Response by Requests_json_parser
Binance = Requests.Get ("
parsed_data = parse_json_Response (binance.text)
print (parsed_data)
These problems may have restrictions or require additional setups. However, you can help you to overcome the problem of accessing data from a URL -API with JSON.
Diploma
In summary, the Binance -API JSON does not use JSON by default and its reply format is simple text. To access data using Python from the API, you must enter the “JSON” parameter or access the response data with other methods such as Parsen Json or the shop in a Python object. While additional setup or library usage may be necessary, these problems can help you to overcome general problems if you work with APIs that do not support JSON.