You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-4Lines changed: 29 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,8 +68,8 @@ if __name__ == '__main__':
68
68
A more complex example follows.
69
69
70
70
```python
71
-
import sys
72
71
import CloudFlare
72
+
import CloudFlare.exceptions
73
73
74
74
defmain():
75
75
zone_name ='example.com'
@@ -79,19 +79,22 @@ def main():
79
79
# query for the zone name and expect only one value back
80
80
try:
81
81
zones = cf.zones.get(params= {'name':zone_name,'per_page':1})
82
-
except CloudFlare.CloudFlareAPIError as e:
82
+
except CloudFlare.exceptions.CloudFlareAPIError as e:
83
83
exit('/zones.get %d%s - api call failed'% (e, e))
84
84
exceptExceptionas e:
85
85
exit('/zones.get - %s - api call failed'% (e))
86
86
87
+
iflen(zones) ==0:
88
+
exit('No zones found')
89
+
87
90
# extract the zone_id which is needed to process that zone
88
91
zone = zones[0]
89
92
zone_id = zone['id']
90
93
91
94
# request the DNS records from that zone
92
95
try:
93
96
dns_records = cf.zones.dns_records.get(zone_id)
94
-
except CloudFlare.CloudFlareAPIError as e:
97
+
except CloudFlare.exceptions.CloudFlareAPIError as e:
95
98
exit('/zones/dns_records.get %d%s - api call failed'% (e, e))
96
99
97
100
# print the results - first the zone name
@@ -171,7 +174,9 @@ You can leave *extras* in the configuration with a blank value (or omit the opti
171
174
172
175
## Exceptions and return values
173
176
174
-
The response is build from the JSON in the API call.
177
+
### Response data
178
+
179
+
The response is build from the JSON in the API call.
175
180
It contains the **results** values; but does not contain the paging values.
176
181
177
182
You can return all the paging values by calling the class with raw=True. Here's an example without paging.
@@ -235,6 +240,26 @@ This produces.
235
240
236
241
A full example of paging is provided below.
237
242
243
+
244
+
### Exceptions
245
+
246
+
The library will raise **CloudFlareAPIError** when the API call fails.
247
+
The exception returns both an integer and textual message in one value.
248
+
249
+
```python
250
+
import CloudFlare
251
+
import CloudFlare.exceptions
252
+
253
+
...
254
+
try
255
+
r =...
256
+
except CloudFlare.exceptions.CloudFlareAPIError as e:
257
+
exit('api error: %d%s'% (e, e))
258
+
...
259
+
```
260
+
261
+
The other raised response is **CloudFlareInternalError** which can happen when calling an invalid method.
262
+
238
263
## Included example code
239
264
240
265
The [examples](https://github.com/cloudflare/python-cloudflare/tree/master/examples) folder contains many examples in both simple and verbose formats.
0 commit comments