diff --git a/requests/utils.py b/requests/utils.py index 563248fb..c5c3fd01 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -115,11 +115,12 @@ def get_netrc_auth(url, raise_errors=False): ri = urlparse(url) - # Strip port numbers from netloc + # Strip port numbers from netloc. This weird `if...encode`` dance is + # used for Python 3.2, which doesn't support unicode literals. + splitstr = b':' if isinstance(url, str): - host = ri.netloc.split(u':')[0] - else: - host = ri.netloc.split(b':')[0] + splitstr = splitstr.decode('ascii') + host = ri.netloc.split(splitstr)[0] try: _netrc = netrc(netrc_path).authenticators(host)