diff --git a/litestar/datastructures/headers.py b/litestar/datastructures/headers.py index 7eceba32ea..fa032103ed 100644 --- a/litestar/datastructures/headers.py +++ b/litestar/datastructures/headers.py @@ -398,15 +398,16 @@ def priority(self) -> tuple[int, int]: # Use fixed point values with two decimals to avoid problems # when comparing float values quality = 100 - if "q" in self.params: + qparam = self.params.get("q") + if qparam is not None: with suppress(ValueError): - quality = int(100 * float(self.params["q"])) + quality = int(100 * float(qparam)) if self.maintype == "*": specificity = 0 elif self.subtype == "*": specificity = 1 - elif not self.params or ("q" in self.params and len(self.params) == 1): + elif not self.params or (qparam is not None and len(self.params) == 1): # no params or 'q' is the only one which we ignore specificity = 2 else: