◐ Shell
clean mode source ↗

Message 282119 - Python tracker

The Python documentation refers to RFC 3986, which allows an empty port string introduced by a colon, although it recommends against it: <https://tools.ietf.org/html/rfc3986#section-3.2.3>

The “port” subcomponent of “authority” is designated by an optional port number in decimal following the host and delimited from it by a single colon. . . . URI producers and normalizers should omit the port component and its “:” delimiter if “port” is empty . . .

What problem are you trying to solve by raising an error?

See also Issue 20059, where accessing the “port” field now raises ValueError for out-of-range values, and Issue 20271, discussing invalid URL handling more generally.