Yes. Here’s the full script I used which generated that error: There is a slight difference from the example in that I’m bypassing TLS cert checking, but otherwise it is the example in the docs:
#!/usr/bin/env python3
import json
import pprint
import urllib.request
import ssl
HOST_NAME = "localhost"
SITE_NAME = "test"
PROTO = "https" #[http|https]
API_URL = f"{PROTO}://{HOST_NAME}/{SITE_NAME}/check_mk/api/1.0"
USERNAME = "cmkadmin"
PASSWORD = "[redacted]"
# don't care about localhost's cert
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
request = urllib.request.Request(
f"{API_URL}/domain-types/service_discovery_run/actions/start/invoke",
method="POST",
headers={
"Authorization": f"Bearer {USERNAME} {PASSWORD}",
"Accept": "application/json",
"Content-Type": 'application/json', # (required) A header specifying which type of content is in the request/response body.
},
data=json.dumps({"host_name": "[redacted]", "mode": "refresh"}).encode('utf-8'),
)
# Will raise an HTTPError if status code is >= 400
resp = urllib.request.urlopen(request, context=ctx)
if resp.status == 200:
pprint.pprint(json.loads(resp.read().decode()))
elif resp.status == 302:
print('Redirected to', resp.headers['location'])
Here’s the full error traceback:
Traceback (most recent call last):
File "/root/./example-redirect-fail.py", line 31, in <module>
resp = urllib.request.urlopen(request, context=ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 215, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 521, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 630, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 553, in error
result = self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 745, in http_error_302
return self.parent.open(new, timeout=req.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 521, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 630, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 553, in error
result = self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 745, in http_error_302
return self.parent.open(new, timeout=req.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 521, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 630, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 553, in error
result = self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 745, in http_error_302
return self.parent.open(new, timeout=req.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 521, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 630, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 553, in error
result = self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 745, in http_error_302
return self.parent.open(new, timeout=req.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 521, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 630, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 553, in error
result = self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/usr/lib64/python3.12/urllib/request.py", line 734, in http_error_302
raise HTTPError(req.full_url, code,
urllib.error.HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
FOUND
Thanks!
Mac