AstronomyAPI / Samples

Examples for Astronomy API
https://astronomyapi.com
MIT License
30 stars 3 forks source link

"Search" Demo Code (python) fails #55

Closed jddavisuk closed 1 year ago

jddavisuk commented 1 year ago

The following python demo code copied directly from the SEARCH console window:-

_import http.client conn = http.client.HTTPSConnection("api.astronomyapi.com") headers = { 'Authorization': "Basic my login deleted" } conn.request("GET", "/api/v2/search?term=polaris&ra=&dec=&matchtype=exact", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))

Fails with the following error message when run in Python 3.9:

_{"statusCode":422,"errors":[{"path":[],"property":"instance","message":"is not exactly one from [subschema 0],[subschema 1]","schema":{"allOf":[{"type":"object","properties":{"limit":{"type":"string","maximum":50,"minimum":1},"offset":{"type":"string","maximum":9999,"minimum":0}}}],"oneOf":[{"type":"object","properties":{"term":{"type":"string","minLength":1},"match_type":{"type":"string","enum":["fuzzy","exact"]},"order_by":{"type":"string","enum":["name"]}},"required":["term"]},{"type":"object","properties":{"ra":{"type":"string","maximum":0,"minimum":360},"dec":{"type":"string","maximum":90,"minimum":-90}},"required":["ra","dec"]}]},"instance":{"dec":"","matchtype":"exact","ra":"","term":"polaris"},"name":"oneOf","argument":["[subschema 0]","[subschema 1]"],"stack":"instance is not exactly one from [subschema 0],[subschema 1]"}]}

Can you please advise a correct python search example:

Thanks

John D

astroanu commented 1 year ago

Interesting, if i run the same script on the python 3.9 terminal it seems to be working fine. You can try the same by running python3 on terminal, copy pasting your code and pressing enter.

I'm suspecting something else is going on in the way you're running it.

jddavisuk commented 1 year ago

Your solution worked. It appears to have been an issue with pasting the code into the editor i was using (nano). Entering the code into nano by hand solved the problem.

Thanks