From 5dd4c0370f7ca78c3b43643fdfe2f0877ec79dcc Mon Sep 17 00:00:00 2001 From: Shashank A Patil Date: Fri, 13 Dec 2024 20:12:41 +0530 Subject: [PATCH] Update run in main.py to handle case when port is not int when port is passed as string it will try converting to integer Then it checks if the port is int and raises ValueError when port is not integer --- uvicorn/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index 96a10d538..45cea901b 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -512,7 +512,13 @@ def run( ) -> None: if app_dir is not None: sys.path.insert(0, app_dir) - + if isinstance(port, str): + try: + port = int(port) + except ValueError: + pass # The next check ensures port is int and not any other type like dict, str etc. + if not isinstance(port, int): + raise ValueError("Port Must Be a valid interger") config = Config( app, host=host,