File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 19
19
logger .addHandler (logging .NullHandler ())
20
20
21
21
ZABBIX_5_4_0 = Version ("5.4.0" )
22
+ ZABBIX_6_4_0 = Version ("6.4.0" )
22
23
23
24
24
25
class ZabbixAPIException (Exception ):
@@ -196,18 +197,28 @@ def do_request(
196
197
"params" : params or {},
197
198
"id" : self .id ,
198
199
}
200
+ headers = {}
199
201
200
202
# We don't have to pass the auth token if asking for
201
203
# the apiinfo.version or user.checkAuthentication
202
204
anonymous_methods = {
203
205
"apiinfo.version" ,
204
206
"user.checkAuthentication" ,
207
+ "user.login" ,
205
208
}
206
209
if self .auth and method not in anonymous_methods :
207
- payload ["auth" ] = self .auth
210
+ if self .version and self .version >= ZABBIX_6_4_0 :
211
+ headers ["Authorization" ] = f"Bearer { self .auth } "
212
+ else :
213
+ payload ["auth" ] = self .auth
208
214
209
215
logger .debug (f"Sending: { payload } " )
210
- resp = self .session .post (self .url , json = payload , timeout = self .timeout )
216
+ resp = self .session .post (
217
+ self .url ,
218
+ json = payload ,
219
+ headers = headers ,
220
+ timeout = self .timeout ,
221
+ )
211
222
logger .debug (f"Response Code: { resp .status_code } " )
212
223
213
224
# NOTE: Getting a 412 response code means the headers are not in the
Original file line number Diff line number Diff line change @@ -268,7 +268,6 @@ def test_do_request(requests_mock, version):
268
268
"jsonrpc" : "2.0" ,
269
269
"method" : "host.get" ,
270
270
"params" : {},
271
- "auth" : "some_auth_key" ,
272
271
"id" : 0 ,
273
272
}
274
273
expect_headers = {
@@ -277,5 +276,10 @@ def test_do_request(requests_mock, version):
277
276
"User-Agent" : "python/pyzabbix" ,
278
277
}
279
278
279
+ if zapi .version < Version ("6.4.0" ):
280
+ expect_json ["auth" ] = "some_auth_key"
281
+ else :
282
+ expect_headers ["Authorization" ] = "Bearer some_auth_key"
283
+
280
284
assert found .json () == expect_json
281
285
assert found .headers .items () >= expect_headers .items ()
You can’t perform that action at this time.
0 commit comments