JSON request and Astroquery basic setup

51 views
Skip to first unread message

Nicolas Flagey

unread,
Aug 10, 2021, 3:27:38 PM8/10/21
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}"'})})
print(R.text)

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
sources.sort('FLUX')
# Reverse to get descending order
sources.reverse()

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',
                                        solve_timeout=300)

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

unread,
Aug 11, 2021, 1:22:34 PM8/11/21
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.

Cheers!

Nicolas Flagey

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