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
After [Issue-114](https://github.com/cloudflare/python-cloudflare/issues/114) was coded and merged, the use of `token` and `key` changed; however, is backward compatible (amazingly!).
197
+
198
+
If you are using only the API Token, then don't include the API Email. If you are coding prior to Issue-114, then the API Key can also be used as an API Token if the API Email is not used.
199
+
200
+
### Python code to create class
181
201
182
202
```python
183
203
import CloudFlare
@@ -191,28 +211,32 @@ import CloudFlare
191
211
# An authenticated call using an API Token (note the missing email)
# An authenticated call using using a stored profile (see below)
201
224
cf = CloudFlare.CloudFlare(profile="CompanyX"))
202
225
```
203
226
204
227
If the account email and API key are not passed when you create the class, then they are retrieved from either the users exported shell environment variables or the .cloudflare.cfg or ~/.cloudflare.cfg or ~/.cloudflare/cloudflare.cfg files, in that order.
205
228
206
-
If you're using an API Token, any `cloudflare.cfg` file must either not contain an `email` attribute or be a zero length string and the `CLOUDFLARE_EMAIL` environment variable must be unset or be a zero length string, otherwise the token will be treated as a key and will throw an error.
229
+
If you're using an API Token, any `cloudflare.cfg` file must either not contain an `email`and `key`attribute (or they can be zero length strings) and the `CLOUDFLARE_EMAIL``CLOUDFLARE_API_KEY`environment variable must be unset (or zero length strings), otherwise the token (`CLOUDFLARE_API_TOKEN` or `token` attribute) will not be used.
207
230
208
231
There is one call that presently doesn't need any email or token certification (the */ips* call); hence you can test without any values saved away.
209
232
210
233
### Using shell environment variables
211
234
212
-
Note (for latest vewrsion of code):
235
+
Note (for latest version of code):
213
236
214
237
*`CLOUDFLARE_EMAIL` has replaced `CF_API_EMAIL`.
215
238
*`CLOUDFLARE_API_KEY` has replaced `CF_API_KEY`.
239
+
*`CLOUDFLARE_API_TOKEN` has replaced `CF_API_TOKEN`.
216
240
*`CLOUDFLARE_API_CERTKEY` has replaced `CF_API_CERTKEY`.
217
241
218
242
Additionally, these two variables are available for testing purposes:
@@ -223,12 +247,19 @@ Additionally, these two variables are available for testing purposes:
223
247
The older environment variable names can still be used.
224
248
225
249
```bash
226
-
$ export CLOUDFLARE_EMAIL='user@example.com'# Do not set if using an API Token
After `Issue-114 <https://github.com/cloudflare/python-cloudflare/issues/114>`__ was coded and merged, the use of ``token`` and ``key`` changed; however, is backward compatible (amazingly!).
202
+
203
+
If you are using only the API Token, then don’t include the API Email. If you are coding prior to Issue-114, then the API Key can also be used as an API Token if the API Email is not used.
204
+
205
+
Python code to create class
206
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
185
207
186
208
.. code:: python
187
209
@@ -196,28 +218,32 @@ When you create a **CloudFlare** class you can pass up to four parameters.
196
218
# An authenticated call using an API Token (note the missing email)
# An authenticated call using using a stored profile (see below)
206
231
cf = CloudFlare.CloudFlare(profile="CompanyX"))
207
232
208
233
If the account email and API key are not passed when you create the class, then they are retrieved from either the users exported shell environment variables or the .cloudflare.cfg or ~/.cloudflare.cfg or ~/.cloudflare/cloudflare.cfg files, in that order.
209
234
210
-
If you’re using an API Token, any ``cloudflare.cfg`` file must either not contain an ``email`` attribute or be a zero length string and the ``CLOUDFLARE_EMAIL`` environment variable must be unset or be a zero length string, otherwise the token will be treated as a key and will throw an error.
235
+
If you’re using an API Token, any ``cloudflare.cfg`` file must either not contain an ``email`` and ``key`` attribute (or they can be zero length strings) and the ``CLOUDFLARE_EMAIL`` ``CLOUDFLARE_API_KEY`` environment variable must be unset (or zero length strings), otherwise the token (``CLOUDFLARE_API_TOKEN`` or ``token`` attribute) will not be used.
211
236
212
237
There is one call that presently doesn’t need any email or token certification (the */ips* call); hence you can test without any values saved away.
213
238
214
239
Using shell environment variables
215
240
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216
241
217
-
Note (for latest vewrsion of code):
242
+
Note (for latest version of code):
218
243
219
244
- ``CLOUDFLARE_EMAIL`` has replaced ``CF_API_EMAIL``.
220
245
- ``CLOUDFLARE_API_KEY`` has replaced ``CF_API_KEY``.
246
+
- ``CLOUDFLARE_API_TOKEN`` has replaced ``CF_API_TOKEN``.
221
247
- ``CLOUDFLARE_API_CERTKEY`` has replaced ``CF_API_CERTKEY``.
222
248
223
249
Additionally, these two variables are available for testing purposes:
@@ -229,11 +255,19 @@ The older environment variable names can still be used.
229
255
230
256
.. code:: bash
231
257
232
-
$ export CLOUDFLARE_EMAIL='user@example.com'# Do not set if using an API Token
These are optional environment variables; however, they do override the values set within a configuration file.
238
272
239
273
Using configuration file to store email and keys
@@ -246,12 +280,12 @@ The default profile name is ``Cloudflare`` for obvious reasons.
246
280
$ cat ~/.cloudflare/cloudflare.cfg
247
281
[Cloudflare]
248
282
email = user@example.com # Do not set if using an API Token
249
-
token = 00000000000000000000000000000000
283
+
key = 00000000000000000000000000000000
250
284
certtoken = v1.0-...
251
285
extras =
252
286
$
253
287
254
-
More than one profile can be stored within that file. Here’s an example for a work and home setup (in this example work has an API Token and home uses email/token).
288
+
More than one profile can be stored within that file. Here’s an example for a work and home setup (in this example work has an API Token and home uses email/key).
255
289
256
290
.. code:: bash
257
291
@@ -260,7 +294,7 @@ More than one profile can be stored within that file. Here’s an example for a
260
294
token = 00000000000000000000000000000000
261
295
[Home]
262
296
email = home@example.com
263
-
token = 00000000000000000000000000000000
297
+
key = 00000000000000000000000000000000
264
298
$
265
299
266
300
To select a profile, use the ``--profile profile-name`` option for ``cli4`` command or use ``profile="profile-name"`` in the library call.
0 commit comments