User-agent header shouldn't start with a space
If the application name, sys.argv[0], is an empty string, like when called from the Ansible os_network module, then keystoneauth (with the new requests 2.11.0) will raise an exception saying: Invalid return character or leading space in header: User-Agent This comes from keystoneauth trying to prepend the empty module name to the default user agent, which leads to it sending a User-Agent header that starts with a blank space. This was fine until the new requests 2.11.0 was released which errors if header values start with a leading space. With this change, if sys.argv[0] is an empty string we'll just use the DEFAULT_USER_AGENT and not try to prepend a calling module. Closes-Bug: #1611426 Change-Id: I56d3e352dce7628add0479b3333a880700844ebc Signed-off-by: Matt Mulsow <mamulsow@us.ibm.com>
This commit is contained in:
parent
c9ae7067bd
commit
4a0ac4583b
@ -155,6 +155,9 @@ def _determine_user_agent():
|
||||
# sys.argv is empty, usually the Python interpreter prevents this.
|
||||
return None
|
||||
|
||||
if not name:
|
||||
return None
|
||||
|
||||
name = os.path.basename(name)
|
||||
if name in ignored:
|
||||
name = _determine_calling_package()
|
||||
|
@ -146,9 +146,11 @@ class SessionTests(utils.TestCase):
|
||||
# If sys.argv[0] is an empty string, then doesn't fail.
|
||||
with mock.patch.object(sys, 'argv', ['']):
|
||||
session = client_session.Session()
|
||||
# NOTE(blk-u): This isn't working right, see bug 1611426
|
||||
self.assertRaises(exceptions.UnknownConnectionError, session.get,
|
||||
self.TEST_URL)
|
||||
resp = session.get(self.TEST_URL)
|
||||
self.assertTrue(resp.ok)
|
||||
self.assertRequestHeaderEqual(
|
||||
'User-Agent',
|
||||
client_session.DEFAULT_USER_AGENT)
|
||||
|
||||
def test_http_session_opts(self):
|
||||
session = client_session.Session(cert='cert.pem', timeout=5,
|
||||
|
Loading…
Reference in New Issue
Block a user