<@ULVA73B9P> I got a JSON decode error. I have hos...
# marvin-ai
a
@Marvin I got a JSON decode error. I have hosted prefect in a local k8s and exposed port 4200 to run a Deployment example
Copy code
from prefect import flow


@flow
def my_flow():
    print("Hello, Prefect!")


if __name__ == "__main__":
    my_flow.serve(name="my-first-deployment", cron="* * * * *", )
I am getting this error
Copy code
mnt/d/d/ca/coral on aniket/add-nemo !3 ?3 ❯ PREFECT_API_URL=<http://127.0.0.1:4200> uv run --package prefect-poc python -m prefect_poc.main         coral with aniket@a100-40gb-vm-group-wrnq at 20:48:09
warning: The `tool.uv.dev-dependencies` field (used in `commons/pyproject.toml`) is deprecated and will be removed in a future release; use `dependency-groups.dev` instead
============== Flow name:  my-flow
============== Deployment name:  my-first-deployment
============== Deployment response:  <Response [200 OK]>
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/mnt/disks/data_disk/causal-labs/coral/prefect_poc/src/prefect_poc/main.py", line 10, in <module>
    my_flow.serve(name="my-first-deployment", cron="* * * * *", )
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/flows.py", line 1119, in serve
    deployment_id = runner.add_flow(
                    ^^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/_internal/compatibility/async_dispatch.py", line 94, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/runner/runner.py", line 522, in add_flow
    ).result()
      ^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 365, in result
    return self.future.result(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 192, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/aniket/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 441, in _run_async
    result = await coro
             ^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/runner/runner.py", line 437, in aadd_flow
    deployment_id = await self.aadd_deployment(deployment)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/runner/runner.py", line 329, in aadd_deployment
    deployment_id = await deployment.aapply()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/deployments/runner.py", line 714, in aapply
    deployment = await client.read_deployment_by_name(self.full_name)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/prefect/client/orchestration/_deployments/client.py", line 1092, in read_deployment_by_name
    print("============== Deployment response json: ", response.json())
                                                       ^^^^^^^^^^^^^^^
  File "/mnt/disks/data_disk/causal-labs/coral/.venv/lib/python3.11/site-packages/httpx/_models.py", line 832, in json
    return jsonlib.loads(self.content, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aniket/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aniket/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aniket/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
m
thought for 367.1 seconds
a
nvm i figured it out, i was missing /api in the API url
Copy code
PREFECT_API_URL=<http://127.0.0.1:4200/api> uv run --package prefect-poc python -m prefect_poc.main
thanks!
m
Thanks for the traceback — this is a classic symptom of pointing the client at the UI root instead of the API. What’s happening - Your
PREFECT_API_URL
is set to
<http://127.0.0.1:4200>
(no
/api
). - Prefect Server mounts the API at the
/api
path. Without it, requests hit the UI (HTML) and
response.json()
fails with a JSONDecodeError even though the status is 200. Fix - Set
PREFECT_API_URL
to include
/api
and try again:
Copy code
export PREFECT_API_URL=<http://127.0.0.1:4200/api>
uv run --package prefect-poc python -m prefect_poc.main
- Or persist it to your current profile:
Copy code
prefect config set PREFECT_API_URL="<http://127.0.0.1:4200/api>"
prefect config view
Quick health checks (should return 200)
Copy code
curl -i <http://127.0.0.1:4200/api/health>
curl -i <http://127.0.0.1:4200/api/ready>
curl -i <http://127.0.0.1:4200/api/version>
If you’re behind an Ingress - Make sure the
/api
path is not being stripped or rewritten to
/
. If you do use a non-root base path, set
PREFECT_SERVER_API_BASE_PATH
to match and point
PREFECT_API_URL
at that full path (e.g., `http://your-host/prefect/api`). Why this is required (docs and refs) - Prefect Server’s API is mounted at `/api`; clients must include it in
PREFECT_API_URL
. See: - Settings and profiles - Self-hosted (Docker Compose) examples (uses
/api
in
PREFECT_API_URL
) - Health endpoints: - GET /api/health - GET /api/ready - GET /api/version Give that a try and let me know if the JSON error goes away. If it persists, share the output of the curl checks above and
prefect config view
so we can dig deeper.