You can use the following code to download file from FMS:
import requests
import json
keycloak_url = "https://keycloak.tp.entsoe.eu/realms/tp/protocol/openid-connect/token"
fms_url = "https://fms.tp.entsoe.eu/listFolder"
username = "YOUR_TP_EMAIL"
password = "YOUR_TP_PASSWORD"
client_id = "tp-fms-public"
# Get token request
payload = {
"client_id": client_id,
"grant_type": "password",
"username": username,
"password": password
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
# List folder content request
response = requests.post(keycloak_url, headers=headers, data=payload)
access_token = response.json().get("access_token")
print(access_token)
payload = json.dumps({
"path": "/TP_export/EnergyPrices_12.1.D_r3/",
"sorterList": [
{
"key": "periodCovered.from",
"ascending": True
}
],
"pageInfo": {
"pageIndex": 0,
"pageSize": 5000
}
})
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
response = requests.request("POST", fms_url, headers=headers, data=payload)
# or
# response = requests.post(fms_url, headers=headers, json=payload)
status_code = response.status_code
if(status_code == 200):
print(response.text)
print("Folder list retrieved.")
else:
print(f"Folder list can not be retrieved, html response status code = {status_code}")
Comments
0 comments
Article is closed for comments.