Hello Guys, at the moment i try to implement a small test-api-call with python (see below). With curl i get a valide response as json-object. With python i get a response, that my authorization ist not valid (401-Response.) See code below. Can somebody help me or give me some hints, thank you!:
import requests
api_url=https://172.168.98.208:9000/api/system?pretty=true ’
bearer_token=‘11111111111111111111’ #dummy-token
headers = {“Authorization:” “{bearer_token}”}
response = requests.get(api_url, headers=headers, verify=False)
print(response.status_code)
The api url isn’t formatted as a string properly.
The Graylog token is used with HTTP Basic authentication.
Here is an example:
import requests
from requests.auth import HTTPBasicAuth
url = "http://hostname.domain.tld/api/"
d_headers = {"Accept":"application/json", "X-Requested-By":"python"}
username = 'apitoken'
password = 'token'
r = requests.post(url, headers=d_headers, verify=False, auth=HTTPBasicAuth(username, password))
Note that when using a token, the username is the contents of the graylog token, and password is token
.
See also Graylog REST API .
system
(system)
Closed
August 19, 2024, 8:49pm
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.