Reputation: 81
I tried this tutorial (https://dev.to/rajshirolkar/fastapi-over-https-for-development-on-windows-2p7d) and then when I went to my browser but I cannot access my localhost address using https, if I try http it works but I need to use HTTPS.
Here is the code I tried:
import uvicorn
if __name__ == "__main__":
uvicorn.run("app.api:app",
host="localhost",
port=8432,
reload=True,
ssl_keyfile="./key.pem",
ssl_certfile="./cert.pem")
Upvotes: 6
Views: 34396
Reputation: 181
Try with this
if __name__ = 'main':
uvicorn.run(
app,
host="0.0.0.0",
port=8432,
ssl_keyfile="./localhost+4-key.pem",
ssl_certfile="./localhost+4.pem"
)
If you pass directly your app
instead the description of attributes app.api:app
you can't use the automatic reload and the workers, but it is an easy way to test if the things are good configured.
Recommendations:
Ensure you are running this command: mkcert localhost 127.0.0.1 ::1
in the folder of your project, also you are probably writing wrong the name of the ssl certificates.
Upvotes: 8
Reputation: 83
If you got this error: "Unsupported upgrade request". Try install uvicorn[standard].
Upvotes: 0