I think the string api_key_id:api_key_secret has to be base64 encoded.
I asked Microsoft Copilot the question: "write the python code to generate an authorization header using basic authentication"
This is the answer:
import base64
def generate_auth_header(username, password):
credentials = f"{username}:{password}"
encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
auth_header = f"Basic {encoded_credentials}"
return auth_header
username = "your_username"
password = "your_password"
header = generate_auth_header(username, password)
print(header)
I am not sure if this could work. I have'nt tried it.