Giter Site home page Giter Site logo

Comments (7)

mahtin avatar mahtin commented on July 24, 2024 1

@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.

mahtin avatar mahtin commented on July 24, 2024

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.

ducphan30 avatar ducphan30 commented on July 24, 2024

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.

mahtin avatar mahtin commented on July 24, 2024

Ah ... 412 ... stay tuned! I'll look at it in a bit but I've seen this before.

from python-cloudflare.

ducphan30 avatar ducphan30 commented on July 24, 2024

Thanks for being reactive !

Please share with me the PR, thanks.

from python-cloudflare.

mahtin avatar mahtin commented on July 24, 2024

@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.

ducphan30 avatar ducphan30 commented on July 24, 2024

Fixed !
Thanks a lot !

from python-cloudflare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.