summaryrefslogtreecommitdiffstats
path: root/lib/bb/fetch2/wget.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bb/fetch2/wget.py')
-rw-r--r--lib/bb/fetch2/wget.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 6dfb27bd9..88349c9bf 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -305,12 +305,24 @@ class Wget(FetchMethod):
r = urllib.request.Request(uri)
r.get_method = lambda: "HEAD"
- if ud.user:
+ def add_basic_auth(login_str, request):
+ '''Adds Basic auth to http request, pass in login:password as string'''
import base64
- encodeuser = base64.b64encode(ud.user.encode('utf-8')).decode("utf-8")
+ encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8")
authheader = "Basic %s" % encodeuser
r.add_header("Authorization", authheader)
+ if ud.user:
+ add_basic_auth(ud.user, r)
+
+ try:
+ import netrc, urllib.parse
+ n = netrc.netrc()
+ login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname)
+ add_basic_auth("%s:%s" % (login, password), r)
+ except (ImportError, IOError, netrc.NetrcParseError):
+ pass
+
opener.open(r)
except urllib.error.URLError as e:
if try_again: