Error 403 for downloading all chunks of snapshot 99 from TNG100

Jeffrey Blunier
  • 1
  • 19 Feb

Dear Dylan,

I have troubles downloading the chunk files of snapshot 99 from TNG100. Here is the following code I am using inspired by the Web API Documentation where I replaced "my-api-key" with the corresponding one:

import requests
import numpy as np
import os
import sys

def get(path, params=None):

# make HTTP GET request to path
headers = {"api-key":"my-api-key"}
r = requests.get(path, params=params, headers=headers)
# raise exception if response code is not HTTP SUCCESS (200)
r.raise_for_status()

if r.headers['content-type'] == 'application/json':
    return r.json() # parse json responses automatically

if 'content-disposition' in r.headers:
    filename = r.headers['content-disposition'].split("filename=")[1]
    with open(filename, 'wb') as f:
        f.write(r.content)
    return filename # return the filename string

return r

def load_file(snapnum,params):
for i in range(448):
if not(os.path.isfile(f"snap_0{snapnum}.{i}.hdf5")):
saved_file = get(f"http://www.tng-project.org/api/TNG100-1/files/snapshot-{snapnum}.{i}.hdf5",params)

if name=='main':
params = {'gas':'Coordinates,MagneticField'}
load_file(int(sys.argv[1]),params)

Running this program as "python3 load_hdf5_files.py 99" leads to the following error:
Traceback (most recent call last):
File "load_hdf5_files.py", line 45, in
load_file(int(sys.argv[1]),params)
File "load_hdf5_files.py", line 35, in load_file
saved_file = get(f"http://www.tng-project.org/api/TNG100-1/files/snapshot-{snapnum}.{i}.hdf5",params)
File "load_hdf5_files.py", line 14, in get
r.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://data-eu.tng-project.org/file/snapshot/L75n1820TNG/99/0/16386.0.0.0.0.0/?token=5f5c57dff28c79648069

It means that I can not even download the first chunk file of snapshot 99 from TNG100. Do you have any idea where it could come from ?

Jeffrey Blunier
  • 19 Feb

It finally worked after multiple attempts, certainly because the server was busy. Sorry for the inconvenience !

  • Page 1 of 1