Python · API

JSON von einer HTTP-API abrufen

Ruft JSON über urllib aus der Python-Standardbibliothek ab.

Python
import json
from urllib.request import Request, urlopen

request = Request("https://example.com/api/status", headers={"User-Agent": "MyApp/1.0"})
with urlopen(request, timeout=10) as response:
    data = json.load(response)

print(data)
PythonHTTPJSONAPI
WA