Browse code

Handle the case where HTTPError.info() returns an object that aren't (#22894)

dict-like enough (can't be used with **).

This should give a better error message for #22872
(cherry picked from commit 29f623571eace54afc98e966c0e1ca66a19d03f2)

Toshio Kuratomi authored on 2017/03/25 04:24:59
Showing 1 changed files
... ...
@@ -1009,8 +1009,16 @@ def fetch_url(module, url, data=None, headers=None, method=None,
1009 1009
             body = e.read()
1010 1010
         except AttributeError:
1011 1011
             body = ''
1012
-        info.update(dict(msg=str(e), body=body, **e.info()))
1013
-        info['status'] = e.code
1012
+
1013
+        # Try to add exception info to the output but don't fail if we can't
1014
+        exc_info = e.info()
1015
+        try:
1016
+            info.update(dict(**e.info()))
1017
+        except:
1018
+            pass
1019
+
1020
+        info.update({'msg': str(e), 'body': body, 'status': e.code})
1021
+
1014 1022
     except urllib_error.URLError:
1015 1023
         e = get_exception()
1016 1024
         code = int(getattr(e, 'code', -1))