How to use the rwslib.rwsobjects.RWSException function in rwslib

To help you get started, we’ve selected a few rwslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdsol / rwslib / rwslib / __init__.py View on Github external
self.request_time = time.time() - start_time
        self.last_result = r  # see also r.elapsed for timedelta object.

        if r.status_code in [400, 404]:
            # Is it a RWS response?
            if r.text.startswith("HTTP Error 401.0 - Unauthorized" in r.text:
                raise RWSException("Unauthorized.", r.text)

            # Check if the content_type is text/xml.  Use startswith
            # in case the charset is also specified:
            #  content-type: text/xml; charset=utf-8
            if r.headers.get("content-type").startswith("text/xml"):
github mdsol / rwslib / rwslib / __init__.py View on Github external
if r.status_code != 200:
            if "<" in r.text:
                # XML like
                if r.text.strip().startswith("
github mdsol / rwslib / rwslib / __init__.py View on Github external
"Server Connection Timeout",
                    "Connection timeout for {}".format(full_url),
                )
            elif isinstance(exc, (requests.exceptions.ReadTimeout,)):
                raise RWSException(
                    "Server Read Timeout", "Read timeout for {}".format(full_url)
                )

        self.request_time = time.time() - start_time
        self.last_result = r  # see also r.elapsed for timedelta object.

        if r.status_code in [400, 404]:
            # Is it a RWS response?
            if r.text.startswith("
github mdsol / rwslib / rwslib / extras / rwscmd / rwscmd.py View on Github external
def direct(ctx, path):
    """Make direct call to RWS, bypassing rwslib"""
    try:
        url = make_url(ctx.obj['RWS'].base_url, path)
        resp = requests.get(url, auth=HTTPBasicAuth(ctx.obj['USERNAME'], ctx.obj['PASSWORD']))
        click.echo(resp.text)
    except RWSException as e:
        click.echo(e.message)
    except requests.exceptions.HTTPError as e:
        click.echo(e.message)
github mdsol / rwslib / rwslib / __init__.py View on Github external
"Server Read Timeout", "Read timeout for {}".format(full_url)
                )

        self.request_time = time.time() - start_time
        self.last_result = r  # see also r.elapsed for timedelta object.

        if r.status_code in [400, 404]:
            # Is it a RWS response?
            if r.text.startswith("HTTP Error 401.0 - Unauthorized" in r.text:
                raise RWSException("Unauthorized.", r.text)

            # Check if the content_type is text/xml.  Use startswith
github mdsol / rwslib / rwslib / __init__.py View on Github external
start_time = time.time()

        try:
            r = action(full_url, **kwargs)  # type: requests.models.Response
        except (
            requests.exceptions.ConnectTimeout,
            requests.exceptions.ReadTimeout,
        ) as exc:
            if isinstance(exc, (requests.exceptions.ConnectTimeout,)):
                raise RWSException(
                    "Server Connection Timeout",
                    "Connection timeout for {}".format(full_url),
                )
            elif isinstance(exc, (requests.exceptions.ReadTimeout,)):
                raise RWSException(
                    "Server Read Timeout", "Read timeout for {}".format(full_url)
                )

        self.request_time = time.time() - start_time
        self.last_result = r  # see also r.elapsed for timedelta object.

        if r.status_code in [400, 404]:
            # Is it a RWS response?
            if r.text.startswith("
github mdsol / rwslib / rwslib / __init__.py View on Github external
)
            elif isinstance(exc, (requests.exceptions.ReadTimeout,)):
                raise RWSException(
                    "Server Read Timeout", "Read timeout for {}".format(full_url)
                )

        self.request_time = time.time() - start_time
        self.last_result = r  # see also r.elapsed for timedelta object.

        if r.status_code in [400, 404]:
            # Is it a RWS response?
            if r.text.startswith("HTTP Error 401.0 - Unauthorized" in r.text:
github mdsol / rwslib / rwslib / __init__.py View on Github external
# Mount a custom adapter that retries failed connections for HTTP and HTTPS requests.
        for scheme in ["http://", "https://"]:
            session.mount(scheme, requests.adapters.HTTPAdapter(max_retries=retries))

        action = {"GET": session.get, "POST": session.post}[request_object.method]

        start_time = time.time()

        try:
            r = action(full_url, **kwargs)  # type: requests.models.Response
        except (
            requests.exceptions.ConnectTimeout,
            requests.exceptions.ReadTimeout,
        ) as exc:
            if isinstance(exc, (requests.exceptions.ConnectTimeout,)):
                raise RWSException(
                    "Server Connection Timeout",
                    "Connection timeout for {}".format(full_url),
                )
            elif isinstance(exc, (requests.exceptions.ReadTimeout,)):
                raise RWSException(
                    "Server Read Timeout", "Read timeout for {}".format(full_url)
                )

        self.request_time = time.time() - start_time
        self.last_result = r  # see also r.elapsed for timedelta object.

        if r.status_code in [400, 404]:
            # Is it a RWS response?
            if r.text.startswith("
github mdsol / rwslib / rwslib / __init__.py View on Github external
error = RWSError(r.text)
            raise RWSException(error.errordescription, error)

        elif r.status_code == 500:
            raise RWSException("Server Error (500)", r.text)

        elif r.status_code == 401:
            # Either you didn't supply auth header and it was required OR your credentials were wrong
            # RWS handles each differently

            # You didn't supply auth (text response from RWS)
            if r.text == "Authorization Header not provided":
                raise AuthorizationException(r.text)

            if "<h2>HTTP Error 401.0 - Unauthorized</h2>" in r.text:
                raise RWSException("Unauthorized.", r.text)

            # Check if the content_type is text/xml.  Use startswith
            # in case the charset is also specified:
            #  content-type: text/xml; charset=utf-8
            if r.headers.get("content-type").startswith("text/xml"):
                # XML response
                if r.text.startswith("