This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: urllib.parse doesn't work with empty port
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: orsenthil, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-01-15 12:26 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
urllib_parse_empty_port.patch serhiy.storchaka, 2014-01-15 12:26 review
Messages (2)
msg208155 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-15 12:26
According to RFC 3986 the port subcomponent is defined as zero or more decimal digits delimited from the host by a single colon. I.e. '' is valid (but not normalized) form. Empty port is equivalent to absent port.

>>> import urllib.parse
>>> p = urllib.parse.urlparse('')
>>> p.hostname
>>> p.port  # should return None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-3.3/Lib/urllib/", line 156, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: ''
>>> urllib.parse.splitport('')  # should return ('', None)
('', None)
>>> urllib.parse.splitnport('')  # should return ('', -1)
('', None)
>>> urllib.parse.splitnport('', 80)  # should return ('', 80)
('', None)

Proposed patch fixes this. It also adds tests for urllib.parse.splitport().
msg208404 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-18 16:32
New changeset a4a51a0d4575 by Serhiy Storchaka in branch '2.7':
Issue #20270: urllib and urlparse now support empty ports.

New changeset 52edc7087c81 by Serhiy Storchaka in branch '3.3':
Issue #20270: urllib.urlparse now supports empty ports.

New changeset 1469c4fde8cd by Serhiy Storchaka in branch 'default':
Issue #20270: urllib.urlparse now supports empty ports.
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64469
2014-01-18 16:33:04serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-01-18 16:32:10python-devsetnosy: + python-dev
messages: + msg208404
2014-01-15 12:37:09serhiy.storchakalinkissue18191 dependencies
2014-01-15 12:32:51serhiy.storchakalinkissue20271 dependencies
2014-01-15 12:26:25serhiy.storchakacreate