Commit 117952cf by James Cammarata

Fixing a bug in the new fetch_url username/password logic

parent b9d8b3b9
...@@ -250,9 +250,8 @@ def fetch_url(module, url, data=None, headers=None, method=None, ...@@ -250,9 +250,8 @@ def fetch_url(module, url, data=None, headers=None, method=None,
handlers.append(ssl_handler) handlers.append(ssl_handler)
if parsed[0] != 'ftp': if parsed[0] != 'ftp':
url_username = module.params.get('url_username', '') username = module.params.get('url_username', '')
if url_username: if username:
username = url_username
password = module.params.get('url_password', '') password = module.params.get('url_password', '')
netloc = parsed[1] netloc = parsed[1]
elif '@' in parsed[1]: elif '@' in parsed[1]:
...@@ -266,19 +265,22 @@ def fetch_url(module, url, data=None, headers=None, method=None, ...@@ -266,19 +265,22 @@ def fetch_url(module, url, data=None, headers=None, method=None,
parsed = list(parsed) parsed = list(parsed)
parsed[1] = netloc parsed[1] = netloc
passman = urllib2.HTTPPasswordMgrWithDefaultRealm() # reconstruct url without credentials
# this creates a password manager url = urlparse.urlunparse(parsed)
passman.add_password(None, netloc, username, password)
# because we have put None at the start it will always
# use this username/password combination for urls
# for which `theurl` is a super-url
authhandler = urllib2.HTTPBasicAuthHandler(passman) if username:
# create the AuthHandler passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
handlers.append(authhandler)
#reconstruct url without credentials # this creates a password manager
url = urlparse.urlunparse(parsed) passman.add_password(None, netloc, username, password)
# because we have put None at the start it will always
# use this username/password combination for urls
# for which `theurl` is a super-url
authhandler = urllib2.HTTPBasicAuthHandler(passman)
# create the AuthHandler
handlers.append(authhandler)
if not use_proxy: if not use_proxy:
proxyhandler = urllib2.ProxyHandler({}) proxyhandler = urllib2.ProxyHandler({})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment