Python request raise invalid CSRF token

CMK version: Checkmk Raw Edition 2.3.0p6
OS version: CentOS7

Error message: Invalid CSRF token

I have a feature to fetch the latest value of service through “Poll Service Data” where I am trying to call Reschedule “Check_Mk” Service API copied from checkmk and executing through python script but it raise invalid CSRF token with user automation.

I tried multiple ways to get latest CSRF token but non of them worked for me. How to get it?
Below is my poll service data script

import requests
from requests.auth import HTTPBasicAuth

# Define the URL
url = "http://192.168.100.61:9000/cmk/check_mk/ajax_reschedule.py?_ajaxid=0"

# Define the username and password
username = "automation"
password = "nms1234567"

# Define the data
data = {
"request": '{"site":"slave1","host":"254","service":"","wait_svc":""}',
"csrf_token": "cda06970-c24f-457b-9696-3be408546315"
}
# Send the POST request with basic auth
response = requests. Post(url, data=data, auth=HTTPBasicAuth(username, password), verify=False)

# Print the response status code and body
print(response.status_code)
print(response. Text)

Output:
200
{“result_code”: 1, “result”: “Invalid CSRF token (‘cda06970-c24f-457b-9696-3be408546315’) for Session (‘3764b205-c472-4a94-bce0-a7a0f688b299’)”, “severity”: “error”}

this is not supported, can’t you use the real Rest API instead of trying to simulate that you are a browser??

I have gone through the API documentation but haven’t got anything related to Reschedule “Check_Mk” Service REST API to fetch the latest value of a particular service.
Can you provide me the API or tell me where to find this API?"

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.