프로그래밍
Python Restful API 클라이언트 예제
warpmemory
2017. 12. 12. 10:32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import requests import json api_url = "https://https://api.warpmemory.com/v1" #auth = ('id', 'passwd') auth = () header = {'Content-Type': 'application/json'} server = "server-001.warpmemory.com" user = "test" passwd = "password" quota = 1000 bandwidth = 2000 domain = "test.warpmemory.com" charset = "utf8" data = { 'passwd': passwd, 'quota': quota, 'bandwidth': bandwidth, 'domain': domain, 'charset': charset } json_data = json.dumps(data) """ 사용자 추가 """ r = requests.post( '%s/hosting/users?server=%s&user=%s' % (api_url, server, user), verify=False, headers=header, data=json_data, auth=auth, timeout=1 ) print r.status_code print r.text """ 사용자 트래픽 제한 변경 """ bandwidth = 3000 data = { 'bandwidth': bandwidth, } json_data = json.dumps(data) r = requests.put( '%s/hosting/users/%s/properties/bandwidth?server=%s' % (api_url, user, server), verify=False, headers=header, data=json_data, auth=auth, timeout=1 ) print r.status_code print r.text """ 사용자 조회 """ r = requests.get( '%s/hosting/users/%s?server=%s' % (api_url, user, server), verify=False, auth=auth, timeout=1 ) print r.status_code print r.text """ 사용자 삭제 """ r = requests.delete( '%s/hosting/users/%s?server=%s' % (api_url, user, server), verify=False, auth=auth, timeout=1 ) print r.status_code print r.text | cs |