From 10f99be100c2a67c435a7b895d0f3ec1185c4df9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 16 Jun 2020 20:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0example=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/example_api.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 utils/example_api.py diff --git a/utils/example_api.py b/utils/example_api.py new file mode 100644 index 000000000..6bc86c665 --- /dev/null +++ b/utils/example_api.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import requests + +# 私有token页面上目前不允许创建,只能后台生成,见 https://docs.jumpserver.org/zh/master/dev/rest_api/ +private_token = '10659d70a223235b8f76d45a3023eca1147488d7' + + +def do_request(url, data=None, method='get', params=None, org_id=''): + authorization = 'Token {}'.format(private_token) + headers = {'Authorization': authorization, 'Content-Type': 'application/json'} + if org_id: + headers['X-JMS-ORG'] = org_id + resp = requests.request(method=method, url=url, data=data, params=params, headers=headers) + return resp + + +def get_assets_list(): + url = 'http://localhost:8080/api/v1/assets/assets/?limit=10' + resp = do_request(url) + print(resp.status_code) + print(resp.json()) + print(resp) + + +if __name__ == '__main__': + get_assets_list() \ No newline at end of file