Reputation: 1
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.
Upvotes: 0
Views: 531
Reputation: 1
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.
Upvotes: 0
Reputation: 11
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.
Upvotes: 1