I am trying to run FastAPI application using uvicorn and I am using Python for this. After running the command "uvicorn app.main:app --host 0.0.0.0 --port 8000 --log-level debug", I am able to get the "Hello" message while accessing the URL but the moment I try to access the swagger document it shows the below error:
Fetch error:
Failed to fetch http://0.0.0.0:8000/openapi.json
Fetch error:
Possible cross-origin (CORS) issue? The URL origin (http://0.0.0.0:8000) does not match the page (http://127.0.0.1:8000). Check the server returns the correct 'Access-Control-Allow-*' headers.
Could anyone please help as I am new to this and kind of struggling.
I am expecting the swagger document to load successfully.
0.0.0.0at all and not just using127.0.0.1? If you plan to use different (local) ips for accessing the service, you'll have to configure CORS as shown in the FastAPI docs for those alternative ips: fastapi.tiangolo.com/tutorial/cors