Samples
Samples copied to clipboard
Bodies Event: always 422 error
What's wrong with this code in Pyhon??? I get always 422 error.
def q3():
# Query 3
payload3 = "{\"observer\":{\"latitude\":27.73,\"longitude\":-15.57,\"elevation\":0,\"from_date\":\"2024-04-30\",\"to_date\":\"2024-04-23\",\"time\":\"23:50:00\"}}"
data = urllib.parse.urlencode(headers)
data = data.encode('ascii') # data should be bytes
conn.request("GET","https://api.astronomyapi.com/api/v2/bodies/events/:moon",payload3,headers)
res = conn.getresponse()
data = res.read()
#print(data.decode("utf-8"))
parsed = json.loads(data.decode("utf-8"))
print(json.dumps(parsed, indent=4))
I always get this error:
"statusCode": 422,
"errors": [
{
"path": [],
"property": "instance",
"message": "requires property \"latitude\"",
"schema": {
"type": "object",
"properties": {
"latitude": {
"type": "number",
"minimum": -90,
"maximum": 90
},
"longitude": {
"type": "number",
"minimum": -180,
"maximum": 180
},
"elevation": {
"type": "number",
"minimum": 0,
"maximum": 5000
},
"from_date": {
"type": "string",
"format": "date"
},
"to_date": {
"type": "string",
"format": "date"
},
"time": {
"type": "string",
"format": "time"
},
"output": {
"type": "string",
"enum": [
"table",
"rows"
]
}
},
"required": [
"latitude",
"longitude",
"elevation",
"from_date",
"to_date",
"time"
]
},...
Thank you
Seems like you're sending the payload as the request body. It needs to sent as url params. See the correct example below.
conn.request("GET", "/api/v2/bodies/positions?longitude=-84.39733&latitude=33.775867&elevation=1&from_date=2024-05-13&to_date=2024-05-13&time=12%3A58%3A06", headers=headers)