Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
request timeout added
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Soloviov committed May 23, 2017
1 parent 6ba5f50 commit 3b091d6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.rst
Expand Up @@ -133,6 +133,22 @@ See the full documentation or install, then use:
python -m egnyte -h
Create configuration
====================

Configuration file will be created in ~/.egnyte/config.json

.. code-block:: python
python -m egnyte config create -d DOMAIN [-l LOGIN] [-p PASSWORD] -k API_KEY [-t ACCESS_TOKEN] [-T TIMEOUT]
Set request timeout
===================

.. code-block:: python
python -m egnyte config update --timeout TIMEOUT_INTEGER
Dependencies
============

Expand Down
3 changes: 2 additions & 1 deletion egnyte/__main__.py
Expand Up @@ -52,6 +52,7 @@ def create_main_parser():

for parser in (parser_config_create, parser_config_update):
parser.add_argument('-t', '--token', dest='access_token', required=False, help='API access token')
parser.add_argument('-T', '--timeout', required=False, help='Request timeout')

# Audit generator

Expand Down Expand Up @@ -140,7 +141,7 @@ def to_json(obj):

class Commands(object):
_config = None
config_keys = ('login', 'password', 'domain', 'api_key', 'access_token')
config_keys = ('login', 'password', 'domain', 'api_key', 'access_token', 'timeout')
STATUS_CMD_NOT_FOUND = 1
STATUS_API_ERROR = 2
INFO = 1
Expand Down
5 changes: 5 additions & 0 deletions egnyte/base.py
Expand Up @@ -16,6 +16,7 @@


JSON_HEADERS = {'content-type': 'application/json'}
DEFAULT_TIMEOUT = 30


class Session(object):
Expand Down Expand Up @@ -48,6 +49,10 @@ def _respect_limits(self):
self.last_request_time = time.time()

def _retry(self, func, *args, **kwargs):

kwargs["timeout"] = int(self.config.get("timeout")) if self.config.get(
"timeout") is not None else DEFAULT_TIMEOUT

while True:
response = func(*args, **kwargs)
if response.headers.get('x-mashery-error-code') == 'ERR_403_DEVELOPER_OVER_QPS':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -9,7 +9,7 @@

args = dict(
name='egnyte',
version='0.5.2',
version='0.5.3',
author='Egnyte',
author_email='api-support@egnyte.com',
license='MIT',
Expand Down

0 comments on commit 3b091d6

Please sign in to comment.