Peter Kim
12/19/2023, 3:52 PMMarvin
12/19/2023, 3:53 PMhttpx
Python library used by Prefect under the hood.
However, the official documentation does not provide specific examples for setting custom headers directly. Instead, standard settings like PREFECT_API_URL
and PREFECT_API_KEY
can be set using the CLI or environment variables. For communication via proxies, you can set the standard HTTPS_PROXY
and SSL_CERT_FILE
variables to configure the httpx
client.
If you need to add a special custom header field to all API requests, here's a general approach that you can take, assuming you're comfortable modifying the underlying HTTP client:
1. Customize the httpx
client instance used by the Prefect client to include your custom headers.
2. Define the custom headers as a dictionary: custom_headers = {"Your-Header-Name": "Your-Header-Value"}
3. Attach these headers to the client instance.
4. Use this custom client when initiating actions with your Prefect on-premises deployment.
You might have to review the Prefect client library's source code or advanced configuration settings (if any) for specifics on implementing custom headers because this is not standard documented behavior.
If this does not suffice, and you still encounter difficulties or need a specific usage example, let me know, and I can help you look further into this, potentially by checking Prefect's GitHub repository for similar issues or code snippets.Peter Kim
12/19/2023, 3:56 PMNate
12/19/2023, 5:24 PMcustom client instance?
Peter Kim
12/19/2023, 5:25 PMPeter Kim
12/19/2023, 5:26 PMNate
12/19/2023, 5:26 PMimport os
import httpx
api_url = os.getenv('PREFECT_API_URL')
headers = {
"Authorization": f"Bearer {os.getenv('PREFECT_API_KEY')}"
}
payload = {
"name": "my-new-flow-run-name", # not required
#"parameters": {} only required if your flow needs params
}
deployment_id = "<my-deployment-uuid>"
async with httpx.AsyncClient() as client:
response = await <http://client.post|client.post>(
f"{api_url}/deployments/{deployment_id}/create_flow_run",
headers=headers,
json=payload
)
response.raise_for_status()
Nate
12/19/2023, 5:26 PMPeter Kim
12/19/2023, 5:27 PMPeter Kim
12/19/2023, 5:27 PMNate
12/19/2023, 5:27 PMwhen I'm calling a flow as if I were calling a function?now, my bad
Peter Kim
12/19/2023, 5:30 PMPeter Kim
12/19/2023, 5:32 PMNate
12/19/2023, 5:33 PMPeter Kim
12/19/2023, 5:34 PMPeter Kim
12/19/2023, 5:34 PMget_client
function in orchestration.py
and swapped it out with a function that adds custom headersPeter Kim
12/19/2023, 5:34 PMPeter Kim
12/19/2023, 5:42 PMPeter Kim
12/19/2023, 5:42 PMPeter Kim
12/19/2023, 5:42 PMPeter Kim
12/19/2023, 5:43 PMcf-access-token