JSON request and Astroquery basic setup

Skip to first unread message

Nicolas Flagey

Aug 10, 2021, 3:27:38 PMAug 10
to astrometry
Hello there,

I am trying to use Astrometry.net automatically from within a Jupyter notebook. I am trying with the request/json and with astroquery.

With requests/json, I first login, as suggested on http://astrometry.net/doc/net/api.html
After that, I have simply tried to check that the session was available by doing:

import requests
import json
# Login
R = requests.post('http://nova.astrometry.net/api/login', data={'request-json': json.dumps({"apikey": "XXXXXXXX"})})
session = R.text.split('"')[-2]
# Request
                  data={'request-json': json.dumps({"session": f'"{session}"'})})

But I am then getting back:
{"status": "error", "errormessage": "no session with key \"\"5es6xgobq02ooddqb5076dns58lz2uw6\"\""}

Same message if I try with the complete example with URL and other parameters on on http://astrometry.net/doc/net/api.html

What am I doing wrong here?

I am also trying astroquery.astrometry_net
I use my API key and a file with X, Y, and FLUX columns.
Here are my lines of code:

sources = Table.read(path + '/astrometrynet_'+str(cl)+'.xyls')
# Sort sources in ascending order
# Reverse to get descending order

image_width = int(max(sources['X']))
image_height = int(max(sources['Y']))
wcs_header = ast.solve_from_source_list(sources['X'], sources['Y'],
                                        image_width, image_height,
                                        center_dec=int(apt_coo.dec.value), center_ra=int(apt_coo.ra.value), radius=5,
                                        scale_lower=1, scale_upper=10, scale_units='arcminwidth',

Where apt_coo is a SkyCoord of my target.
This prints Solving....... before stopping without any other message (definitely stopping before 300sec).

print(wcs_header) returns an empty dictionary

Does that mean it failed to solve or something else?

Wilfred Tyler Gee

Aug 11, 2021, 1:22:34 PMAug 11
to astrometry
Hi Nicolas,

In the first case, it looks like you are just double-quoting your session key here: f'"{session}"'. You can change it to: f'{session}'. (This was very hard to see with the default font in your example but you can put in monospace for most emails).

Also, instead of the hacky session = R.text.split('"')[-2], you can just access the json() method of the response: session = R.json()['session'].

Not sure about the astroquery example.


Nicolas Flagey

Aug 12, 2021, 9:10:47 AMAug 12
to astrometry
Thanks! Indeed those quotes were the issue :)
I can now remotely access Astrometry, yeeha!
Reply all
Reply to author
0 new messages