Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"):
if r.status_code != 200:
if "<" in r.text:
# XML like
if r.text.strip().startswith("
"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("
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)
"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
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("
if r.text.strip().startswith("
)
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:
# 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("
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("