简体   繁体   中英

How can I debug this python code?

I am trying to use a python wrapper to post to an API.

When I step into the following code from the library in pycharm

    # Make the request
    self._make_request(
        self.BASE_URI + method,
        params.encode("utf-8"),
    )

it jumps to this retry method

def retry(ExceptionToCheck, tries=3, delay=2, backoff=2):
    """
    Retry decorator published by Saltry Crane.

    http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
    """

I think that it jumps there because of the following decorator in _make_request (altho I do not understand Python decorators yet):

@retry(Exception, tries=3)
def _make_request(self, url, params=None, opener=None):

However, I am at a dead end because if I set breakpoints in @retry and look at the ExceptionToCheck it just shows a blank BaseException with no message and no args.

Does this code somehow skip the _make_request method (this is what the step into implies in pycharm) or does it somehow just jump to @retry.

What are the next steps that I can take to debug this?

保持步进- retry作为_make_request的包装器_make_request ,它将最终调用该代码。

A decorator wraps a function. That means, when you call a function that has a decorator, the decorator function is called instead. But the decorator function will then (usually) in turn call the decorated one. So, you need to keep stepping through retry until you get to the bit where it calls the original function. Since the original was a parameter to the decorator, you'll probably see something like return func(*args) or whatever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM