You've already forked akaunting-py
Added exception to catch rate-limiting.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import requests
|
||||
import logging
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
from akauntingpy import exceptions
|
||||
from akauntingpy.helpers import *
|
||||
|
||||
__version__ = "1.0.3"
|
||||
__version__ = "1.0.5"
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Client(object):
|
||||
"""
|
||||
Akaunting interface.
|
||||
@@ -68,6 +71,9 @@ class Client(object):
|
||||
"\n".join(errors))
|
||||
# elif response.status_code != 200 and response.status_code != 201:
|
||||
# raise exceptions.Error(response_['message'])
|
||||
elif response.status_code == 429:
|
||||
# We hit the maximum requests
|
||||
raise exceptions.TooManyAttempts(response_['message'])
|
||||
return response_
|
||||
|
||||
def ping(self):
|
||||
@@ -162,9 +168,15 @@ class Client(object):
|
||||
transferred_at=None, # Date of expense/transfer or income
|
||||
payment_method="Bank Transfer", # Payment method
|
||||
amount=None, # Amount received/paid
|
||||
**params # Any additional parameters
|
||||
**params # Any additional parameters
|
||||
):
|
||||
|
||||
logger.info("Transfer called with parameters")
|
||||
logger.info("from_account_id: %s", from_account_id)
|
||||
logger.info("to_account_id: %s", to_account_id)
|
||||
logger.info("transferred_at: %s", transferred_at)
|
||||
logger.info("payment_method: %s", payment_method)
|
||||
logger.info("amount: %s", amount)
|
||||
|
||||
data = self.call(endpoint="transfers",
|
||||
method="POST",
|
||||
from_account_id=from_account_id,
|
||||
|
||||
@@ -31,6 +31,14 @@ class ContactNotFound(Error):
|
||||
"""
|
||||
Account not found
|
||||
|
||||
Args:
|
||||
Error (_type_): _description_
|
||||
"""
|
||||
|
||||
class TooManyAttempts(Error):
|
||||
"""
|
||||
Too Many attempts to API
|
||||
|
||||
Args:
|
||||
Error (_type_): _description_
|
||||
"""
|
||||
Reference in New Issue
Block a user