From b24c037f6213f9aae9a198848826c9352cf6c604 Mon Sep 17 00:00:00 2001 From: lumean Date: Thu, 11 Apr 2019 17:28:44 +0200 Subject: [PATCH] fix 'APIC Error 403: padding check failed' in python3 (#55150) * fix 'APIC Error 403: padding check failed' in python3 With python2 the APIC-Request-Signature is filled in correctly APIC-Request-Signature=aAvxASu... But with python3 the string format method seems to add the encoding to the output, causing a padding error: APIC-Request-Signature=b'lFmHWvwW4dr... Reproduce: # -*- coding: utf-8 -*- import base64 a = base64.b64encode(b'\u0001') b = '%s' % a print(b) ======= python --version; python test.py Python 2.7.16 :: Anaconda, Inc. XHUwMDAx Python 3.6.3 :: Anaconda, Inc. b'XHUwMDAx' * Ensure we use native strings --- lib/ansible/module_utils/network/aci/aci.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/network/aci/aci.py b/lib/ansible/module_utils/network/aci/aci.py index 017099b27b3..bb58f12a938 100644 --- a/lib/ansible/module_utils/network/aci/aci.py +++ b/lib/ansible/module_utils/network/aci/aci.py @@ -39,7 +39,7 @@ from copy import deepcopy from ansible.module_utils.parsing.convert_bool import boolean from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.urls import fetch_url -from ansible.module_utils._text import to_bytes +from ansible.module_utils._text import to_bytes, to_native # Optional, only used for APIC signature-based authentication try: @@ -267,7 +267,7 @@ class ACIModule(object): self.headers['Cookie'] = 'APIC-Certificate-Algorithm=v1.0; ' +\ 'APIC-Certificate-DN=%s; ' % sig_dn +\ 'APIC-Certificate-Fingerprint=fingerprint; ' +\ - 'APIC-Request-Signature=%s' % sig_signature + 'APIC-Request-Signature=%s' % to_native(sig_signature) def response_json(self, rawoutput): ''' Handle APIC JSON response output '''