-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from rbw0/branch-0.6.9
Branch 0.6.9
- Loading branch information
Showing
13 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Exceptions | ||
========== | ||
|
||
.. automodule:: pysnow.exceptions | ||
|
||
Generic Exceptions | ||
------------------ | ||
.. autoclass:: InvalidUsage | ||
|
||
Response Exceptions | ||
------------------- | ||
.. autoclass:: ResponseError | ||
.. autoclass:: MissingResult | ||
.. autoclass:: UnexpectedResponseFormat | ||
.. autoclass:: ReportUnavailable | ||
.. autoclass:: NoResults | ||
.. autoclass:: MultipleResults | ||
|
||
OAuthClient Exceptions | ||
---------------------- | ||
.. autoclass:: MissingToken | ||
.. autoclass:: TokenCreateError | ||
|
||
QueryBuilder Exceptions | ||
----------------------- | ||
.. autoclass:: QueryTypeError | ||
.. autoclass:: QueryMissingField | ||
.. autoclass:: QueryEmpty | ||
.. autoclass:: QueryExpressionError | ||
.. autoclass:: QueryMultipleExpressions | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Session with auto-retry | ||
======================= | ||
|
||
You might run into issues if you're creating too many requests against the ServiceNow API. | ||
Fortunately, the `requests` library enables users to create their own transport adapter with a retry mechanism from the `urllib3` library. | ||
|
||
You can read more about transport adapters and the retry mechanism here: | ||
- http://docs.python-requests.org/en/master/user/advanced/#transport-adapters | ||
- https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry | ||
|
||
|
||
This example shows how to automatically retry on an error for about 2 seconds and then fall back to the default error handling. | ||
|
||
.. code-block:: python | ||
import requests | ||
import pysnow | ||
from requests.adapters import HTTPAdapter | ||
from requests.packages.urllib3.util.retry import Retry | ||
s = requests.Session() | ||
s.auth = requests.auth.HTTPBasicAuth('<username>', '<password>') | ||
# set auto retry for about 2 seconds on some common errors | ||
adapter = HTTPAdapter( | ||
max_retries=Retry( | ||
total=3, | ||
backoff_factor=0.3, | ||
status_forcelist=(401, 408, 429, 431, 500, 502, 503, 504, 511) | ||
) | ||
) | ||
s.mount('https://', adapter) | ||
sn = pysnow.Client(instance='<instance>', session=s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Using threaded queries | ||
====================== | ||
|
||
This is an example of multiple threads doing simple fetches. | ||
|
||
|
||
.. note:: | ||
This example uses `concurrent.futures` and expects you to be familiar with :meth:`pysnow.Resource.get`. | ||
|
||
|
||
.. code-block:: python | ||
import concurrent.futures | ||
import pysnow | ||
def just_print(client, query): | ||
# Run the query | ||
response = client.get(query=query) | ||
# Iterate over the result and print out `sys_id` and `state` of the matching records. | ||
for record in response.all(): | ||
print(record['sys_id'], record['state']) | ||
# Create client object | ||
c = pysnow.Client(instance='myinstance', user='myusername', password='mypassword') | ||
# list of simple items to query | ||
queries = ({'api': '/table/incident', 'q': {'state': 1}}, {'api': '/table/incident', 'q': {'state': 3}}) | ||
# build taskqueue | ||
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as taskpool: | ||
for query in queries: | ||
connection = c.resource(api_path=query['api']) | ||
taskpool.submit(just_print, connection, query['q']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,10 @@ | |
from .oauth_client import OAuthClient | ||
from .query_builder import QueryBuilder | ||
from .resource import Resource | ||
from .params_builder import ParamsBuilder | ||
|
||
__author__ = "Robert Wikman <[email protected]>" | ||
__version__ = "0.6.8" | ||
__version__ = "0.6.9" | ||
|
||
# Set default logging handler to avoid "No handler found" warnings. | ||
import logging | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters