|
4 | 4 | import requests |
5 | 5 |
|
6 | 6 | def call(auth, method, endpoint, params=None): |
7 | | - response = requests.request(method, |
8 | | - 'https://api.cloudflare.com/client/v4/' + endpoint, |
9 | | - headers={ "X-Auth-Email": auth['EMAIL'], |
10 | | - "X-Auth-Key": auth['TOKEN'] }, |
11 | | - params=params |
12 | | - ) |
13 | | - data = response.text |
14 | | - try: |
15 | | - data = json.loads(data) |
16 | | - return data |
17 | | - except ValueError: |
18 | | - raise CloudFlareAPIError('JSON parse failed.') |
19 | | - if data['result'] == 'error': |
20 | | - raise CloudFlareAPIError(data['msg']) |
| 7 | + logging.debug('auth') |
| 8 | + logging.debug('method') |
| 9 | + logging.debug('endpoint') |
| 10 | + logging.debug('params') |
| 11 | + if (auth is None) or (method is None) or (endpoint is None): |
| 12 | + raise CloudFlareError('You must specify auth, method, and endpoint') |
| 13 | + else: |
| 14 | + response = requests.request(method, |
| 15 | + 'https://api.cloudflare.com/client/v4/' + endpoint, |
| 16 | + headers={ "X-Auth-Email": auth['EMAIL'], |
| 17 | + "X-Auth-Key": auth['TOKEN'] }, |
| 18 | + params=params |
| 19 | + ) |
| 20 | + data = response.text |
| 21 | + logging.debug('data') |
| 22 | + try: |
| 23 | + data = json.loads(data) |
| 24 | + return data |
| 25 | + except ValueError: |
| 26 | + raise CloudFlareAPIError('JSON parse failed.') |
| 27 | + if data['result'] == 'error': |
| 28 | + raise CloudFlareAPIError(data['msg']) |
0 commit comments