api

已查看 293 次
跳至第一个未读帖子

Connors Cubing

未读,
2022年5月11日 11:57:232022/5/11
收件人 astrometry
im trying to use the api but when i try to use it with this code (api key and other sensitive stuff left out):

#imports
import requests
import json
import time

#vars
jl = []

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

#get session
Rr = json.loads(R.text)
s = Rr['session']

#open the pic
files = {'file': open('/X/X/X/X.jpg', 'rb')}

#upload pic
r = requests.post('http://nova.astrometry.net/api/upload', files=files, data={'request-json': json.dumps({"apikey": "XXXXXX", "session": str(s), "publicly_visible": 'n'})})
print(r.text)

#get the submission id
St = json.loads(r.text)
t = St['subid']
print(t)

#get the job id
while jl == []:
    if jl == []:
        st = requests.post(f'http://nova.astrometry.net/api/submissions/{t}', data={'request-json': json.dumps({"apikey": "XXXXXX", "session": str(s)})})
        print(st.text)
        j = json.loads(st.text)
        jl = j['jobs']
    if jl != []:
        job = jl[0]
        print(str(job))
    time.sleep(2)

i just get these errors:
ValueError: invalid literal for int() with base 16: b'!\x90\xf9\x1c\xd0\x00\x00\x00'

urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length
 b'!\x90\xf9\x1c\xd0\x00\x00\x00', 0 bytes read)

urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'!\\x90\\xf9\\x1c\\xd0\\x00\\x00\\x00', 0 bytes read)", InvalidChunkLength(got length b'!\x90\xf9\x1c\xd0\x00\x00\x00', 0 bytes read))

requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'!\\x90\\xf9\\x1c\\xd0\\x00\\x00\\x00', 0 bytes read)", InvalidChunkLength(got length b'!\x90\xf9\x1c\xd0\x00\x00\x00', 0 bytes read))

to me it seems like somewhere an encoded string is being corrupted or something similar to that

Connors Cubing

未读,
2022年5月11日 11:57:592022/5/11
收件人 astrometry
also please let me know if that encoded string includes my api key so i can delete the post

Dustin Lang

未读,
2022年5月16日 17:05:322022/5/16
收件人 astrometry
Hi,

You know there is a Python client program/library, right?

My guess is that you need to use HTTPS rather than HTTP, but I could be wrong.  From your posting, I don't see which line that error message is coming from.  If you can post the full stack track in the standard format, that would be useful.

cheers,
dustin

Yanis Gougeat

未读,
2022年5月25日 10:06:502022/5/25
收件人 astrometry
Hello,

I'm getting the same trouble. Yesterday the script was working fine, but today it is no longer working whereas my code did not change. My python code is similar to the Connors' one but I have the same error message. I can confirm you that using HTTPS rather than HTTP is not the solution.

here is the entire error code:

Traceback (most recent call last):
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 700, in _update_chunk_length
    self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b'\x89\xba\xcf\xac\x15\x00\x00\x00'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 441, in _error_catcher
    yield
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 767, in read_chunked  
    self._update_chunk_length()
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 704, in _update_chunk_length
    raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'\x89\xba\xcf\xac\x15\x00\x00\x00', 0 bytes read)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 760, in generate        
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 575, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 755, in read_chunked  
    with self._error_catcher():
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\response.py", line 458, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'\\x89\\xba\\xcf\\xac\\x15\\x00\\x00\\x00', 0 bytes read)", InvalidChunkLength(got length b'\x89\xba\xcf\xac\x15\x00\x00\x00', 0 bytes read))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Yanis Gougeat\Documents\Astrometry.net API\test.py", line 41, in <module>
    R = requests.post('https://nova.astrometry.net/api/jobs/' + str(6497390), data={'request-json': json.dumps({"session": session_key})})
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 529, in request      
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 687, in send
    r.content
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 838, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File "C:\Users\Yanis Gougeat\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 763, in generate        
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'\\x89\\xba\\xcf\\xac\\x15\\x00\\x00\\x00', 0 bytes read)", InvalidChunkLength(got length b'\x89\xba\xcf\xac\x15\x00\x00\x00', 0 bytes read))


I hope you can help me ;)

Yanis

Dustin Lang

未读,
2022年5月25日 11:52:382022/5/25
收件人 Yanis Gougeat、astrometry
We have been having some trouble with the server the last few days -- it's possible that this is some 503 error message that your code is trying to interpret as something different, or HTTP to HTTPS forwarding working differently.

--
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/f18b8680-30a7-44d7-8be3-ea9f5c7627dfn%40googlegroups.com.
回复全部
回复作者
转发
0 个新帖子