How to deploy to a Prefect Server with basic auto on? #17262
-
Based on https://docs.prefect.io/v3/deploy/infrastructure-concepts/deploy-via-python#deploy-flows-with-python if __name__ == "__main__":
my_flow.deploy(
name="my-deployment",
work_pool_name="hm-work-pool",
image="ghcr.io/hongbo-miao/hm-prefect-print-platform:latest",
push=False
) When I deploy, I got error python src/deploy.py --environment=development
Traceback (most recent call last):
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/src/deploy.py", line 31, in <module>
asyncio.run(deploy())
~~~~~~~~~~~^^^^^^^^^^
File "/Users/hongbo-miao/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 194, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "/Users/hongbo-miao/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Users/hongbo-miao/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/src/deploy.py", line 26, in deploy
await create_deployment(args.environment, main, image, deployment)
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/src/workflow_deploy/utils/create_deployment.py", line 16, in create_deployment
await workflow.deploy(
...<6 lines>...
)
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/.venv/lib/python3.13/site-packages/prefect/utilities/asyncutils.py", line 341, in ctx_call
result = await async_fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/.venv/lib/python3.13/site-packages/prefect/flows.py", line 1459, in deploy
work_pool = await client.read_work_pool(work_pool_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/.venv/lib/python3.13/site-packages/prefect/client/orchestration/_work_pools/client.py", line 416, in read_work_pool
response = await self.request(
^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/.venv/lib/python3.13/site-packages/prefect/client/orchestration/base.py", line 53, in request
return await self._client.send(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/.venv/lib/python3.13/site-packages/prefect/client/base.py", line 354, in send
response.raise_for_status()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/hongbo-miao/Clouds/Git/hongbomiao.com/data-orchestration/hm-prefect/workflows/print-platform/.venv/lib/python3.13/site-packages/prefect/client/base.py", line 162, in raise_for_status
raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__
prefect.exceptions.PrefectHTTPStatusError: Client error '401 Unauthorized' for url 'https://prefect.hongbomiao.com/api/work_pools/hm-work-pool'
Response: {'exception_message': 'Unauthorized'}
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 My Prefect Server has basic auth on, with I do have I tried to run |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @hongbo-miao! You need to set the auth string setting for the client before running your deploy script. You can do that by running |
Beta Was this translation helpful? Give feedback.
Hey @hongbo-miao! You need to set the auth string setting for the client before running your deploy script. You can do that by running
export PREFECT_API_AUTH_STRING=admin:my_password
. You can find more info in the security settings section of the docs here.