Requests Returning Empty Content (status_code 204)

Question:

UPDATE:

Ok, so my cookie attempt only worked temporarily, as I was hardcoding a cookie in from inspecting the page, I assume because the cookie expired.

My code currently looks like this, but still gets 204 on the response:

with requests.Session() as session:
    resp = session.post('https://space-track.org/auth/login',data={'identity':user,'password':pswd})
    
    url = 'https://www.space-track.org/basicspacedata/query/class/gp_history/NORAD_CAT_ID/{}/orderby/TLE_LINE1%20ASC/EPOCH/2022-05-25--{}-{}-{}/format/tle'
    ids = {
        'Object1':15430,
        'Object2':25430
        }
    for name,catid in ids.items():
        newrl = url.format(catid,year,month,day+1)
        resp = session.get(url)
        print(resp)

Any other thoughts?

ORIGINAL:

I’m trying to automate the collection of data from space-track.org as it becomes available.

When I execute the following code, the text/content come back empty and the status code is 204. I saw some other response suggesting a loop with a sleep timer in it but that did not resolve the issue.

>>> import requests
>>> url = 'https://www.space-track.org/basicspacedata/query/class/gp_history/NORAD_CAT_ID/54031/orderby/TLE_LINE1%20ASC/EPOCH/2022-05-25--2022-10-13/format/tle'
>>> r = requests.get(url,headers={'User-Agent':'Mozilla/5.0'})
>>> r.text
''

Am I missing headers or something else? I’m not overly experienced with this type of task.

Thanks.

Asked By: Joseph White

||

Answers:

When I access your link I get redirected to a login page. It is protected by authorisation/authentication.
I assume you have to add credentials or token in headers, to your request, in order to access the content of the page.

Answered By: dyna-soar

I’ve resolved my problem, I had a typo in my code that was using the url template in the get request as opposed to the updated ‘newrl’ that was correct.

Answered By: Joseph White
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.