Comments (7)
@ducphan30 - ok, I've replicated this and you are 100% correct. This wasn't coded fully and the error was not returned. I've written code that replaces this and with the updated code I now see the error message vs 412. I will craft a new release of the package today or tomorrow and message you here. Thank for you pointing this out.
Just for the record, you can replicate this error via the following calls that create a pool, use it on a zone, then try to delete the pool before removing it from the zone. Once it's removed from the zone, you can delete the pool.
Create pool:
/accounts/:account_id/load_balancers/pools POST
Success
Create load balancer:
/zones/:zone_id/load_balancers POST
Success
Try to delete pool:
/accounts/:account_id/load_balancers/pools DELETE
Error expected: 1005 This object is referenced by other objects, delete them first.
Now remove pool from zone:
/zones/:zone_id/load_balancers DELETE
Success
Now delete pool:
/accounts/:account_id/load_balancers/pools DELETE
Success
from python-cloudflare.
The exception provides a return value and that can be looked at.
$ python
>>> import CloudFlare
>>> cf = CloudFlare.CloudFlare()
>>> try:
... r = cf.zones('00000000')
... except CloudFlare.exceptions.CloudFlareAPIError as e:
... print('%d %s' % (int(e), str(e)))
...
7003 Could not route to /client/v4/zones/00000000, perhaps your object identifier is invalid?
>>>
>>> try:
... r = cf.zones('00000000000000000000000000000000')
... except CloudFlare.exceptions.CloudFlareAPIError as e:
... print('%d %s' % (int(e), str(e)))
...
9109 Invalid zone identifier
>>>
This is the normal way to show the message returned when something produces an exception of type CloudFlare.exceptions.CloudFlareAPIError
.
However, if you read the Cloudflare API documents you will see that some API's call can return more than one error message, this following code will help decode all the messages:
except CloudFlare.exceptions.CloudFlareAPIError as e:
if len(e) > 0:
# more than one error returned by the API
for x in e:
# print the extra error codes
print('%d %s\n' % (int(x), str(x)))
# print the core error code
print('%d %s\n' % (int(e), str(e)))
# continue with error code
This is all documented at https://github.com/cloudflare/python-cloudflare#exceptions
from python-cloudflare.
Thanks for your reply.
I've read the documentation before opening this issue 😉
Unfortunately, I think that for some specific API calls, the error messages management is not fully implemented as the above code snippet you wrote.
Example with this API call: https://developers.cloudflare.com/api/operations/account-load-balancer-pools-delete-pool
The returned message is 412 HTTP response code 412
when a pool is being used by another load balancer (with your code snippet).
from python-cloudflare.
Ah ... 412
... stay tuned! I'll look at it in a bit but I've seen this before.
from python-cloudflare.
Thanks for being reactive !
Please share with me the PR, thanks.
from python-cloudflare.
@ducphan30 - please upgrade to 2.17.0
. It took a few edits to get this generically fixed; however, after testing a ton of API calls that produce 4xx
(ie. 421
and other 4xx
errors like 401
etc) I'm happy with this release. Your load balancer example now works correctly.
Please close the issue if you are happy with the release. Thanks.
from python-cloudflare.
Fixed !
Thanks a lot !
from python-cloudflare.
Related Issues (20)
- Deposit
- How to access R2 storage to perform CRUD on Bucket and Objects HOT 3
- Token authentication fails when using python-cloudflare versions above 2.8.15 HOT 8
- python-cloudflare is not PEP-561 aware HOT 2
- UnicodeDecodeError: 'gbk' codec can't decode byte 0x88 in position 16820: illegal multibyte sequence HOT 2
- HTTP method calls should be able to define content-header (headers) HOT 6
- Image error: /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tests/__init__.py HOT 8
- 1012 Request must contain one of "purge_everything", "files", "tags", "hosts" or "prefixes" HOT 8
- Change WAF Custom Rule with wrong position HOT 1
- CloudFlareError does not evaluate to true if there are no chained errors HOT 7
- Bad request for direct image upload HOT 6
- Regression in 2.18.0 HOT 8
- Would like to be able to pass in my own HTTP headers HOT 11
- Docs: Provide information on how arguments are mapped to API paths HOT 6
- URL creation doesn't ensure strings for parameters HOT 3
- Is max_requests_retries still valid? HOT 2
- Deprecate support for python3.5 HOT 3
- Possible error in README example HOT 2
- ModuleNotFoundError: No module named 'CloudFlare' after cloudflare dependency update HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-cloudflare.