File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change 218
218
from ansible .plugins .inventory import BaseInventoryPlugin , Constructable , Cacheable
219
219
from ansible .module_utils .ansible_release import __version__ as ansible_version
220
220
from ansible .errors import AnsibleError
221
- from ansible .module_utils ._text import to_text
221
+ from ansible .module_utils ._text import to_text , to_native
222
222
from ansible .module_utils .urls import open_url
223
+ from ansible .module_utils .six .moves .urllib import error as urllib_error
223
224
from ansible .module_utils .six .moves .urllib .parse import urlencode
224
225
from ansible_collections .ansible .netcommon .plugins .module_utils .compat .ipaddress import (
225
226
ip_interface ,
@@ -254,12 +255,19 @@ def _fetch_information(self, url):
254
255
255
256
if need_to_fetch :
256
257
self .display .v ("Fetching: " + url )
257
- response = open_url (
258
- url ,
259
- headers = self .headers ,
260
- timeout = self .timeout ,
261
- validate_certs = self .validate_certs ,
262
- )
258
+ try :
259
+ response = open_url (
260
+ url ,
261
+ headers = self .headers ,
262
+ timeout = self .timeout ,
263
+ validate_certs = self .validate_certs ,
264
+ )
265
+ except urllib_error .HTTPError as e :
266
+ """This will return the response body when we encounter an error.
267
+ This is to help determine what might be the issue when encountering an error.
268
+ Please check issue #294 for more info.
269
+ """
270
+ raise AnsibleError (to_native (e .fp .read ()))
263
271
264
272
try :
265
273
raw_data = to_text (response .read (), errors = "surrogate_or_strict" )
You can’t perform that action at this time.
0 commit comments