Skip to content

Commit c0fe72f

Browse files
committed
utils: Use hostname for netrc instead split netloc
This patch uses the "hostname" attribute from the parsed url to get the host, instead of trying to calculate the host from netloc that can produce errors when "http://username:[email protected]" format is used.
1 parent f72c4d1 commit c0fe72f

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

src/requests/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,7 @@ def get_netrc_auth(url, raise_errors=False):
236236
return
237237

238238
ri = urlparse(url)
239-
240-
# Strip port numbers from netloc. This weird `if...encode`` dance is
241-
# used for Python 3.2, which doesn't support unicode literals.
242-
splitstr = b":"
243-
if isinstance(url, str):
244-
splitstr = splitstr.decode("ascii")
245-
host = ri.netloc.split(splitstr)[0]
239+
host = ri.hostname
246240

247241
try:
248242
_netrc = netrc(netrc_path).authenticators(host)

0 commit comments

Comments
 (0)