Closed fhg-isi closed 2 months ago
Possible solution: mock browser headers:
def open_remote_excel_file(url, sheet_name):
temp_xlsx_path = 'temp_dummy_file.xlsx'
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
req = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(req) as response:
with open(temp_xlsx_path, "wb") as output_file:
output_file.write(response.read())
df = pd.read_excel(temp_xlsx_path, sheet_name=sheet_name)
os.remove(temp_xlsx_path)
return df
Describe the Bug
When trying to run
build_gas_input_location.py
usingI get the error message below.
I am able to manually download the excel file when entering the url into a browser:
http://globalenergymonitor.org/wp-content/uploads/2023/07/Europe-Gas-Tracker-2023-03-v3.xlsx
Maybe the webpage has some restrictions for automated downloads?
Error Message
Related:
https://github.com/PyPSA/pypsa-eur/issues/1118