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