A
A
avdoshka2021-11-29 16:22:26
Python
avdoshka, 2021-11-29 16:22:26

How to declare two Python variables in one class?

Good day to all, please help me to understand the code.

import task
class TooManyRequests(Exception):
      """Too many requests"""
@task(
   rate_limit='10/s',
   autoretry_for=(ConnectTimeout, TooManyRequests,),
   retry_backoff=True)
def api(*args, **kwargs):
  r = requests.get('placeholder-external-api')

  if r.status_code == 429:
    raise TooManyRequests() 
Выдает ошибку
in <module>
    autoretry_for=(ConnectTimeout, TooManyRequests,),
NameError: name 'ConnectTimeout' is not defined

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LXSTVAYNE, 2021-11-29
@avdoshka

You didn't import ConnectTimeout from some package, most likely from requests.exceptions. https://docs.python-requests.org/en/master/_module...

V
Vasily, 2021-11-29
@snaiper04ek

you didn't set ConnectTimeout to anything. Presumably, you need either task.ConnectTimeout, or forgot the import from somewhere, or give the github, because nothing is clear. (well, or provide the sources of the entire chain of imports)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question