`--quic-bind 0.0.0.0:4433` fails to listen on port 4433 and browser fails to reach my application
khteh opened this issue · comments
pipenv run hypercorn --reload --quic-bind 0.0.0.0:4433 --certfile server.crt --keyfile server.key --bind 0.0.0.0:8080 src.main:app
[2024-01-24 13:26:10 +0800] [39801] [INFO] Running on https://0.0.0.0:8080 (CTRL + C to quit)
2024-01-24 13:26:10 INFO Running on https://0.0.0.0:8080 (CTRL + C to quit)
[2024-01-24 13:26:10 +0800] [39801] [INFO] Running on https://0.0.0.0:4433 (QUIC) (CTRL + C to quit)
2024-01-24 13:26:10 INFO Running on https://0.0.0.0:4433 (QUIC) (CTRL + C to quit)
https://localhost:4433/ fails. What happen?
This is a long standing bug.
--quic-bind just refuses to be reachable outside localhost. i.e. 0.0.0.0 will fail
It doesn't work also with localhost!
pipenv run hypercorn --reload --quic-bind localhost:4433 --certfile server.crt --keyfile server.key --bind 0.0.0.0:8080 src.main:app
[2024-03-12 16:44:47 +0800] [365961] [INFO] Running on https://0.0.0.0:8080 (CTRL + C to quit)
2024-03-12 16:44:47 INFO Running on https://0.0.0.0:8080 (CTRL + C to quit)
[2024-03-12 16:44:47 +0800] [365961] [INFO] Running on https://127.0.0.1:4433 (QUIC) (CTRL + C to quit)
2024-03-12 16:44:47 INFO Running on https://127.0.0.1:4433 (QUIC) (CTRL + C to quit)
Any update on this!?! How can I use this library to serve H3!?!
I don't think browsers try HTTP/3 by default, you'll need to serve over HTTP/1 or HTTP/2 and send an alt-serve header. Here is an example.
I comment out server_names
as I don't know how useful it is to reach the app from browser. Using the following config,
accesslog = "/var/log/pythonrestapi"
errorlog = "/var/log/pythonrestapi"
alt_svc_headers = ["h3=\":443\"; ma=3600, h3-29=\":443\"; ma=3600"]
quic_bind = "0.0.0.0:4433"
bind = "0.0.0.0:4433"
insecure_bind = "0.0.0.0:8080"
certfile = "server.crt"
keyfile = "server.key"
#server_names = ["pythonrestapi"]
worker_class = "trio"
and run pipenv run hypercorn --config=hypercorn.toml --reload src.main:app
, I hit the following runtime error:
2024-05-29 13:12:17 INFO Running on https://0.0.0.0:4433 (CTRL + C to quit)
2024-05-29 13:12:17 INFO Running on http://0.0.0.0:8080 (CTRL + C to quit)
2024-05-29 13:12:17 INFO Running on https://0.0.0.0:4433 (QUIC) (CTRL + C to quit)
2024-05-29 13:12:26 ERROR Error in ASGI Framework
Traceback (most recent call last):
File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/hypercorn/trio/task_group.py", line 26, in _handle
await app(scope, receive, send, sync_spawn, call_soon)
File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
await self.app(scope, receive, send)
File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/quart/app.py", line 1667, in __call__
await self.asgi_app(scope, receive, send)
File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/quart/app.py", line 1693, in asgi_app
await asgi_handler(receive, send)
File "/home/khteh/.local/share/virtualenvs/PythonRestAPI-6TwrpjXm/lib/python3.12/site-packages/quart/asgi.py", line 48, in __call__
done, pending = await asyncio.wait(
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/tasks.py", line 463, in wait
loop = events.get_running_loop()
^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: no running event loop
src/main.py
:
from src.app import create_app
app = create_app()
app = cors(app, allow_credentials=True, allow_origin="https://localhost:4433")
Healthz(app, no_log=True)
csrf = CSRFProtect(app)
bcrypt.init_app(app)
src/app.py
:
def create_app() -> Quart:
"""
Create App
"""
# App initialization
app = Quart(__name__, template_folder='view/templates', static_url_path='', static_folder='view/static')
app.config.from_file("/etc/pythonrestapi_config.json", json.load)
if "SQLALCHEMY_DATABASE_URI" not in app.config:
app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql://{os.getenv('POSTGRESQL_USER')}:{os.getenv('POSTGRESQL_PASSWORD')}@svc-postgresql/library"
app.register_blueprint(home_blueprint, url_prefix="/")
app.register_blueprint(fibonacci_blueprint, url_prefix="/fibonacci")
app.register_blueprint(auth_blueprint, url_prefix="/auth")
app.register_blueprint(user_blueprint, url_prefix="/users")
app.register_blueprint(author_blueprint, url_prefix="/authors")
app.register_blueprint(book_blueprint, url_prefix="/books")
db.init_app(app)
return app
Hello, I tried to load .toml
config file programmatically but it still doesn't work:
from hypercorn.config import Config
config = Config()
config.from_toml("/etc/pythonrestapi.toml")
asyncio.run(serve(app, config))
This is all I see in the terminal when running it through pipenv run hypercorn --reload src.main:app
:
[2024-06-01 11:28:40 +0800] [100003] [INFO] Running on http://127.0.0.1:8000 (CTRL + C to quit)
2024-06-01 11:28:40 INFO Running on http://127.0.0.1:8000 (CTRL + C to quit)