I am trying to connect to this endpoint and hoping to receive a excel file:
"https://api.refinitiv.com/data/change-notifications/v1/published-notifications/211744/attachments/DN_ContentsetANDProduct_Impact.xlsx/.tWLIDJLHSzhZ1zBnHqOboyu8CqsFKMF"
It works when I try and connect using the API Playground but not locally.
However, I get a ConnectionResetError 104. I am able to get a token using this endpoint:
"https://api.refinitiv.com/auth/oauth2/v1/token". And I am also able to connect other endpoints.
Is there a reason I cannot access this endpoint locally? Does it something to do with it returning an excel file? This is my code:
TOKEN_URL = "https://api.refinitiv.com/auth/oauth2/v1/token"
DATA_URL = "https://api.refinitiv.com/data/change-notifications/v1/published-notifications/211744/attachments/DN_ContentsetANDProduct_Impact.xlsx/.tWLIDJLHSzhZ1zBnHqOboyu8CqsFKMF"
def get_token(user: str, password: str, api_key: str): request_body = { "username": user, "password": password, "grant_type": "password", "scope": "trapi", "takeExclusiveSignOnControl": True, } response = requests.post( TOKEN_URL, headers={}, data=request_body, auth=(api_key, ""), timeout=30.0 ) response.raise_for_status() return json.loads(response.text.encode("ascii", "ignore"))
def get_data(token: str) -> str: headers = { "Authorization": f"Bearer {token}", "Accept": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } response = requests.request("GET", DATA_URL, headers=headers, data={}) response.raise_for_status() return response.content
cred = get_credentials("lsegapi")
tok = get_token(user=cred.user, password=cred.password, api_key="cfd7d81fca5b40749db0217a59e438f5f49a0926")
data = get_data(tok["access_token"])
data