@@ -407,16 +407,23 @@ def get_file_checksum(self):
407407 return self .sha256_hash .hexdigest ()
408408
409409
410- def _download_file (url , outfile ):
410+ def _download_file (url , outfile , github_token = None ):
411411 """Downloads the MCEq database from github"""
412412
413413 import math
414414
415415 import requests
416416 from tqdm import tqdm
417417
418+ headers = {}
419+ if github_token :
420+ headers ["Authorization" ] = f"token { github_token } "
421+
418422 # Streaming, so we can iterate over the response.
419- r = requests .get (url , stream = True )
423+ r = requests .get (url , stream = True , headers = headers )
424+
425+ if r .status_code != 200 :
426+ raise Exception (f"Download failed with status { r .status_code } " )
420427
421428 # Total size in bytes.
422429 total_size = int (r .headers .get ("content-length" , 0 ))
@@ -455,7 +462,11 @@ def _download_file(url, outfile):
455462 print (f"Downloading for mceq database file { mceq_db_fname } ." )
456463 if debug_level >= 2 :
457464 print (url )
458- _download_file (url , filepath_to_database )
465+
466+ import os
467+
468+ github_token = os .environ .get ("GITHUB_TOKEN" )
469+ _download_file (url , filepath_to_database , github_token = github_token )
459470
460471old_database = "mceq_db_lext_dpm191_v12.h5"
461472filepath_to_old_database = data_dir / old_database
0 commit comments