Re: [Astrometry] How to upload a picture via python

323 views
Skip to first unread message
Message has been deleted

Dustin Lang

unread,
Apr 16, 2020, 10:01:09 AM4/16/20
to Fede, astrometry
Hi,

We have a stand-alone command-line client in python:

cheers,
--dustin

On Thu, Apr 16, 2020 at 10:00 AM Fede <federica.l...@gmail.com> wrote:
Hi, I need to upload to nova.astrometry.net a picture and then download the correspondent RA and DEC. 
I've used the requests methods with the API url, but it doesn't upload the image.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/86aaff62-7f26-40cc-af69-724cda9a5b22%40googlegroups.com.

Fede

unread,
Apr 16, 2020, 10:25:06 AM4/16/20
to astro...@googlegroups.com
Sorry, I don't get it, I thought I had to use the requests form like:

R = requests.post('http://nova.astrometry.net/api/login', data={'request-json': json.dumps({"apikey": "XXXX"})})
url = 'http://nova.astrometry.net/api/upload'
files = {'file': open('XXX','rb')}
r = requests.post(url,files=files)

Il giorno giovedì 16 aprile 2020 16:01:09 UTC+2, Dustin Lang ha scritto:
Hi,

We have a stand-alone command-line client in python:

cheers,
--dustin

On Thu, Apr 16, 2020 at 10:00 AM Fede <federica....@gmail.com> wrote:
Hi, I need to upload to nova.astrometry.net a picture and then download the correspondent RA and DEC. 
I've used the requests methods with the API url, but it doesn't upload the image.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.

Dustin Lang

unread,
Apr 16, 2020, 10:40:15 AM4/16/20
to Fede, astrometry
Oh, I see, you're looking at the docs.... the docs really should be updated to suggest that people just use the client.py library...

Are you including the session key when you're trying to do your file upload?

"You have to include that “session” value in all subsequent requests."

That is, your second POST must also include a "request-json" field.

cheers,
--dustin


On Thu, Apr 16, 2020 at 10:25 AM Fede <federica.l...@gmail.com> wrote:
Sorry, I don't get it, I thought I had to use the requests form like:

R = requests.post('http://nova.astrometry.net/api/login', data={'request-json': json.dumps({"apikey": "XXXX"})})
print(R.text)

url = 'http://nova.astrometry.net/api/upload'
files = {'file': open('XXX','rb')}
r = requests.post(url,files=files)
print(r.status_code)

Il giorno giovedì 16 aprile 2020 16:01:09 UTC+2, Dustin Lang ha scritto:
Hi,

We have a stand-alone command-line client in python:

cheers,
--dustin

On Thu, Apr 16, 2020 at 10:00 AM Fede <federica....@gmail.com> wrote:
Hi, I need to upload to nova.astrometry.net a picture and then download the correspondent RA and DEC. 
I've used the requests methods with the API url, but it doesn't upload the image.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/86aaff62-7f26-40cc-af69-724cda9a5b22%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/900f6d68-ca86-4229-a6c9-bb47352aeba3%40googlegroups.com.

Fede

unread,
Apr 16, 2020, 10:58:14 AM4/16/20
to astrometry
No, I didn't, where should I add the session key?


Il giorno giovedì 16 aprile 2020 16:40:15 UTC+2, Dustin Lang ha scritto:
Oh, I see, you're looking at the docs.... the docs really should be updated to suggest that people just use the client.py library...

Are you including the session key when you're trying to do your file upload?

"You have to include that “session” value in all subsequent requests."

That is, your second POST must also include a "request-json" field.

cheers,
--dustin


On Thu, Apr 16, 2020 at 10:25 AM Fede <federica....@gmail.com> wrote:
Sorry, I don't get it, I thought I had to use the requests form like:

R = requests.post('http://nova.astrometry.net/api/login', data={'request-json': json.dumps({"apikey": "XXXX"})})
print(R.text)
url = 'http://nova.astrometry.net/api/upload'
files = {'file': open('XXX','rb')}
r = requests.post(url,files=files)
print(r.status_code)

Il giorno giovedì 16 aprile 2020 16:01:09 UTC+2, Dustin Lang ha scritto:
Hi,

We have a stand-alone command-line client in python:

cheers,
--dustin

On Thu, Apr 16, 2020 at 10:00 AM Fede <federica....@gmail.com> wrote:
Hi, I need to upload to nova.astrometry.net a picture and then download the correspondent RA and DEC. 
I've used the requests methods with the API url, but it doesn't upload the image.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/86aaff62-7f26-40cc-af69-724cda9a5b22%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astro...@googlegroups.com.

Dustin Lang

unread,
Apr 16, 2020, 11:03:34 AM4/16/20
to Fede, astrometry
I haven't used 'requests' much, so I'm not certain this is how it works, but

files = {'file': open('XXX','rb'),
    'request-json': json.dumps({"session": "YYYY"})}

where YYYY comes from parsing the result you got from logging in (R.text).

The format expected is what would be sent if there was an HTML form with a text box called "request-json" plus a file upload field.

cheers,
--dustin

JST200

unread,
Apr 16, 2020, 11:28:02 AM4/16/20
to astrometry
Hi,

I have a Python program that uploads images to nova and then displays the results. You can either use it with its GUI or using command line. The command line provides a lot more options than the GUI.

It's an extension of the example python program given on the website. The only thing is you need to install Python 2.7 to use it.

You are more than welcome to have a copy. If nothing else it will give you an example of the python calls to Nova. There's a post on the APT Forum, which I think you should be able to view. If not, let me know.

https://aptforum.com/phpbb/viewtopic.php?f=24&t=1820&hilit=novasolve

Cheers, Jim

Fede

unread,
Apr 16, 2020, 11:29:35 AM4/16/20
to astrometry
Thank you, but it returns {"status": "error", "errormessage": "no json"} 
:(
Reply all
Reply to author
Forward
Message has been deleted
0 new messages