Last active
March 28, 2019 18:16
-
-
Save ryandawsonuk/94e17c0d28ce241d5b2b94f87949b580 to your computer and use it in GitHub Desktop.
failures from E2E log ambassador 2 pr445
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
=================================== FAILURES =================================== | |
______________________ TestClusterWide.test_abtest_model _______________________ | |
deploymentName = 'myabtest', namespace = 'test1', endpoint = 'localhost:8003' | |
data_size = 5, rows = 1, data = None | |
def grpc_request_ambassador2(deploymentName,namespace,endpoint="localhost:8004",data_size=5,rows=1,data=None): | |
try: | |
> grpc_request_ambassador(deploymentName,namespace,endpoint=endpoint,data_size=data_size,rows=rows,data=data) | |
seldon_utils.py:127: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
args = ('myabtest', 'test1') | |
kw = {'data': None, 'data_size': 5, 'endpoint': 'localhost:8003', 'rows': 1} | |
@six.wraps(f) | |
def wrapped_f(*args, **kw): | |
> return Retrying(*dargs, **dkw).call(f, *args, **kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:49: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <retrying.Retrying object at 0x7f5f07444ac8> | |
fn = <function grpc_request_ambassador at 0x7f5f07471d08> | |
args = ('myabtest', 'test1') | |
kwargs = {'data': None, 'data_size': 5, 'endpoint': 'localhost:8003', 'rows': 1} | |
start_time = 1553794360439, attempt_number = 7 | |
attempt = Attempts: 7, Error: | |
File "/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py", line 200, in call | |
attem...ckages/grpc/_channel.py", line 466, in _end_unary_response_blocking | |
raise _Rendezvous(state, None, None, deadline) | |
tb = (<class 'grpc._channel._Rendezvous'>, <_Rendezvous of RPC that terminated with: | |
status = StatusCode.UNIMPLEMENTED | |
de...ore/lib/surface/call.cc","file_line":1039,"grpc_message":"","grpc_status":12}" | |
>, <traceback object at 0x7f5f073818c8>) | |
delay_since_first_attempt_ms = 44068, sleep = 10000 | |
def call(self, fn, *args, **kwargs): | |
start_time = int(round(time.time() * 1000)) | |
attempt_number = 1 | |
while True: | |
try: | |
attempt = Attempt(fn(*args, **kwargs), attempt_number, False) | |
except: | |
tb = sys.exc_info() | |
attempt = Attempt(tb, attempt_number, True) | |
if not self.should_reject(attempt): | |
return attempt.get(self._wrap_exception) | |
delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time | |
if self.stop(attempt_number, delay_since_first_attempt_ms): | |
if not self._wrap_exception and attempt.has_exception: | |
# get() on an attempt with an exception should cause it to be raised, but raise just in case | |
> raise attempt.get() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:212: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Attempts: 7, Error: | |
File "/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py", line 200, in call | |
attem...ckages/grpc/_channel.py", line 466, in _end_unary_response_blocking | |
raise _Rendezvous(state, None, None, deadline) | |
wrap_exception = False | |
def get(self, wrap_exception=False): | |
""" | |
Return the return value of this Attempt instance or raise an Exception. | |
If wrap_exception is true, this Attempt is wrapped inside of a | |
RetryError before being raised. | |
""" | |
if self.has_exception: | |
if wrap_exception: | |
raise RetryError(self) | |
else: | |
> six.reraise(self.value[0], self.value[1], self.value[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:247: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
tp = <class 'grpc._channel._Rendezvous'>, value = None, tb = None | |
def reraise(tp, value, tb=None): | |
try: | |
if value is None: | |
value = tp() | |
if value.__traceback__ is not tb: | |
raise value.with_traceback(tb) | |
> raise value | |
/home/ryan/anaconda3/lib/python3.7/site-packages/six.py:693: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <retrying.Retrying object at 0x7f5f07444ac8> | |
fn = <function grpc_request_ambassador at 0x7f5f07471d08> | |
args = ('myabtest', 'test1') | |
kwargs = {'data': None, 'data_size': 5, 'endpoint': 'localhost:8003', 'rows': 1} | |
start_time = 1553794360439, attempt_number = 7 | |
attempt = Attempts: 7, Error: | |
File "/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py", line 200, in call | |
attem...ckages/grpc/_channel.py", line 466, in _end_unary_response_blocking | |
raise _Rendezvous(state, None, None, deadline) | |
tb = (<class 'grpc._channel._Rendezvous'>, <_Rendezvous of RPC that terminated with: | |
status = StatusCode.UNIMPLEMENTED | |
de...ore/lib/surface/call.cc","file_line":1039,"grpc_message":"","grpc_status":12}" | |
>, <traceback object at 0x7f5f073818c8>) | |
delay_since_first_attempt_ms = 44068, sleep = 10000 | |
def call(self, fn, *args, **kwargs): | |
start_time = int(round(time.time() * 1000)) | |
attempt_number = 1 | |
while True: | |
try: | |
> attempt = Attempt(fn(*args, **kwargs), attempt_number, False) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:200: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
deploymentName = 'myabtest', namespace = 'test1', endpoint = 'localhost:8003' | |
data_size = 5, rows = 1, data = None | |
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7) | |
def grpc_request_ambassador(deploymentName,namespace,endpoint="localhost:8004",data_size=5,rows=1,data=None): | |
if data is None: | |
shape, arr = create_random_data(data_size,rows) | |
else: | |
shape = data.shape | |
arr = data.flatten() | |
datadef = prediction_pb2.DefaultData( | |
tensor = prediction_pb2.Tensor( | |
shape = shape, | |
values = arr | |
) | |
) | |
request = prediction_pb2.SeldonMessage(data = datadef) | |
channel = grpc.insecure_channel(endpoint) | |
stub = prediction_pb2_grpc.SeldonStub(channel) | |
if namespace is None: | |
metadata = [('seldon',deploymentName)] | |
else: | |
metadata = [('seldon',deploymentName),('namespace',namespace)] | |
> response = stub.Predict(request=request,metadata=metadata) | |
seldon_utils.py:122: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <grpc._channel._UnaryUnaryMultiCallable object at 0x7f5f074624e0> | |
request = data { | |
tensor { | |
shape: 1 | |
shape: 5 | |
values: 0.035389019392884746 | |
values: 0.1274069060865466 | |
values: 0.07270839318975275 | |
values: 0.8243990478046658 | |
values: 0.1982425374070994 | |
} | |
} | |
timeout = None, metadata = [('seldon', 'myabtest'), ('namespace', 'test1')] | |
credentials = None, wait_for_ready = None | |
def __call__(self, | |
request, | |
timeout=None, | |
metadata=None, | |
credentials=None, | |
wait_for_ready=None): | |
state, call, = self._blocking(request, timeout, metadata, credentials, | |
wait_for_ready) | |
> return _end_unary_response_blocking(state, call, False, None) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/grpc/_channel.py:549: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
state = <grpc._channel._RPCState object at 0x7f5f074109b0> | |
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f5f07482d88> | |
with_call = False, deadline = None | |
def _end_unary_response_blocking(state, call, with_call, deadline): | |
if state.code is grpc.StatusCode.OK: | |
if with_call: | |
rendezvous = _Rendezvous(state, call, None, deadline) | |
return state.response, rendezvous | |
else: | |
return state.response | |
else: | |
> raise _Rendezvous(state, None, None, deadline) | |
E grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with: | |
E status = StatusCode.UNIMPLEMENTED | |
E details = "" | |
E debug_error_string = "{"created":"@1553794404.506104111","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1039,"grpc_message":"","grpc_status":12}" | |
E > | |
/home/ryan/anaconda3/lib/python3.7/site-packages/grpc/_channel.py:466: _Rendezvous | |
During handling of the above exception, another exception occurred: | |
self = <test_helm_charts_clusterwide.TestClusterWide object at 0x7f5f073e9dd8> | |
def test_abtest_model(self): | |
run("helm delete myabtest --purge", shell=True) | |
run("helm install ../../helm-charts/seldon-abtest --name myabtest --set oauth.key=oauth-key --set oauth.secret=oauth-secret --namespace test1", shell=True, check=True) | |
wait_for_rollout("myabtest-abtest-41de5b8") | |
wait_for_rollout("myabtest-abtest-df66c5c") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret","test1",API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
r = rest_request_ambassador("myabtest","test1",API_AMBASSADOR) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
r = grpc_request_api_gateway2("oauth-key","oauth-secret","test1",rest_endpoint=API_GATEWAY_REST,grpc_endpoint=API_GATEWAY_GRPC) | |
print(r) | |
> r = grpc_request_ambassador2("myabtest","test1",API_AMBASSADOR) | |
test_helm_charts_clusterwide.py:75: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:130: in grpc_request_ambassador2 | |
grpc_request_ambassador(deploymentName,namespace,endpoint=endpoint,data_size=data_size,rows=rows,data=data) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:49: in wrapped_f | |
return Retrying(*dargs, **dkw).call(f, *args, **kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:212: in call | |
raise attempt.get() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:247: in get | |
six.reraise(self.value[0], self.value[1], self.value[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/six.py:693: in reraise | |
raise value | |
/home/ryan/anaconda3/lib/python3.7/site-packages/retrying.py:200: in call | |
attempt = Attempt(fn(*args, **kwargs), attempt_number, False) | |
seldon_utils.py:122: in grpc_request_ambassador | |
response = stub.Predict(request=request,metadata=metadata) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/grpc/_channel.py:549: in __call__ | |
return _end_unary_response_blocking(state, call, False, None) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
state = <grpc._channel._RPCState object at 0x7f5f07410438> | |
call = <grpc._cython.cygrpc.SegregatedCall object at 0x7f5f0740ea48> | |
with_call = False, deadline = None | |
def _end_unary_response_blocking(state, call, with_call, deadline): | |
if state.code is grpc.StatusCode.OK: | |
if with_call: | |
rendezvous = _Rendezvous(state, call, None, deadline) | |
return state.response, rendezvous | |
else: | |
return state.response | |
else: | |
> raise _Rendezvous(state, None, None, deadline) | |
E grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with: | |
E status = StatusCode.UNIMPLEMENTED | |
E details = "" | |
E debug_error_string = "{"created":"@1553794448.591975887","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1039,"grpc_message":"","grpc_status":12}" | |
E > | |
/home/ryan/anaconda3/lib/python3.7/site-packages/grpc/_channel.py:466: _Rendezvous | |
____________________ TestSingleNamespace.test_single_model _____________________ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
> (self._dns_host, self.port), self.timeout, **extra_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:159: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
sock.connect(sa) | |
return sock | |
except socket.error as e: | |
err = e | |
if sock is not None: | |
sock.close() | |
sock = None | |
if err is not None: | |
> raise err | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:80: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
> sock.connect(sa) | |
E ConnectionRefusedError: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:70: ConnectionRefusedError | |
During handling of the above exception, another exception occurred: | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0737f9e8> | |
method = 'POST', url = '/seldon/test1/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.5496043072363148, 0.6785797578753154, 0.5777703956227764, 0.8826402545288229]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f052aad30> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0737fc88> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
> chunked=chunked) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:600: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0737f9e8> | |
conn = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
method = 'POST', url = '/seldon/test1/mymodel/api/v0.1/predictions' | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0737fc88> | |
chunked = False | |
httplib_request_kw = {'body': b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.54960430723631...p, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'}} | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0737fa90> | |
def _make_request(self, conn, method, url, timeout=_Default, chunked=False, | |
**httplib_request_kw): | |
""" | |
Perform a request on a given urllib connection object taken from our | |
pool. | |
:param conn: | |
a connection from one of our connection pools | |
:param timeout: | |
Socket timeout in seconds for the request. This can be a | |
float or integer, which will set the same timeout value for | |
the socket connect and the socket read, or an instance of | |
:class:`urllib3.util.Timeout`, which gives you more fine-grained | |
control over your timeouts. | |
""" | |
self.num_requests += 1 | |
timeout_obj = self._get_timeout(timeout) | |
timeout_obj.start_connect() | |
conn.timeout = timeout_obj.connect_timeout | |
# Trigger any extra validation we need to do. | |
try: | |
self._validate_conn(conn) | |
except (SocketTimeout, BaseSSLError) as e: | |
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout. | |
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) | |
raise | |
# conn.request() calls httplib.*.request, not the method in | |
# urllib3.request. It also calls makefile (recv) on the socket. | |
if chunked: | |
conn.request_chunked(method, url, **httplib_request_kw) | |
else: | |
> conn.request(method, url, **httplib_request_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:354: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
method = 'POST', url = '/seldon/test1/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.5496043072363148, 0.6785797578753154, 0.5777703956227764, 0.8826402545288229]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
def request(self, method, url, body=None, headers={}, *, | |
encode_chunked=False): | |
"""Send a complete request to the server.""" | |
> self._send_request(method, url, body, headers, encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1229: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
method = 'POST', url = '/seldon/test1/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.5496043072363148, 0.6785797578753154, 0.5777703956227764, 0.8826402545288229]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
encode_chunked = False | |
def _send_request(self, method, url, body, headers, encode_chunked): | |
# Honor explicitly requested Host: and Accept-Encoding: headers. | |
header_names = frozenset(k.lower() for k in headers) | |
skips = {} | |
if 'host' in header_names: | |
skips['skip_host'] = 1 | |
if 'accept-encoding' in header_names: | |
skips['skip_accept_encoding'] = 1 | |
self.putrequest(method, url, **skips) | |
# chunked encoding will happen if HTTP/1.1 is used and either | |
# the caller passes encode_chunked=True or the following | |
# conditions hold: | |
# 1. content-length has not been explicitly set | |
# 2. the body is a file or iterable, but not a str or bytes-like | |
# 3. Transfer-Encoding has NOT been explicitly set by the caller | |
if 'content-length' not in header_names: | |
# only chunk body if not explicitly set for backwards | |
# compatibility, assuming the client code is already handling the | |
# chunking | |
if 'transfer-encoding' not in header_names: | |
# if content-length cannot be automatically determined, fall | |
# back to chunked encoding | |
encode_chunked = False | |
content_length = self._get_content_length(body, method) | |
if content_length is None: | |
if body is not None: | |
if self.debuglevel > 0: | |
print('Unable to determine size of %r' % body) | |
encode_chunked = True | |
self.putheader('Transfer-Encoding', 'chunked') | |
else: | |
self.putheader('Content-Length', str(content_length)) | |
else: | |
encode_chunked = False | |
for hdr, value in headers.items(): | |
self.putheader(hdr, value) | |
if isinstance(body, str): | |
# RFC 2616 Section 3.7.1 says that text default has a | |
# default charset of iso-8859-1. | |
body = _encode(body, 'body') | |
> self.endheaders(body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1275: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.5496043072363148, 0.6785797578753154, 0.5777703956227764, 0.8826402545288229]}}}' | |
def endheaders(self, message_body=None, *, encode_chunked=False): | |
"""Indicate that the last header line has been sent to the server. | |
This method sends the request to the server. The optional message_body | |
argument can be used to pass a message body associated with the | |
request. | |
""" | |
if self.__state == _CS_REQ_STARTED: | |
self.__state = _CS_REQ_SENT | |
else: | |
raise CannotSendHeader() | |
> self._send_output(message_body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1224: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.5496043072363148, 0.6785797578753154, 0.5777703956227764, 0.8826402545288229]}}}' | |
encode_chunked = False | |
def _send_output(self, message_body=None, encode_chunked=False): | |
"""Send the currently buffered request and clear the buffer. | |
Appends an extra \\r\\n to the buffer. | |
A message_body may be specified, to be appended to the request. | |
""" | |
self._buffer.extend((b"", b"")) | |
msg = b"\r\n".join(self._buffer) | |
del self._buffer[:] | |
> self.send(msg) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1016: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
data = b'POST /seldon/test1/mymodel/api/v0.1/predictions HTTP/1.1\r\nHost: localhost:8003\r\nUser-Agent: python-requests/2.21...zip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 173\r\nContent-Type: application/json\r\n\r\n' | |
def send(self, data): | |
"""Send `data' to the server. | |
``data`` can be a string object, a bytes object, an array object, a | |
file-like object that supports a .read() method, or an iterable object. | |
""" | |
if self.sock is None: | |
if self.auto_open: | |
> self.connect() | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:956: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
def connect(self): | |
> conn = self._new_conn() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:181: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
(self._dns_host, self.port), self.timeout, **extra_kw) | |
except SocketTimeout as e: | |
raise ConnectTimeoutError( | |
self, "Connection to %s timed out. (connect timeout=%s)" % | |
(self.host, self.timeout)) | |
except SocketError as e: | |
raise NewConnectionError( | |
> self, "Failed to establish a new connection: %s" % e) | |
E urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8>: Failed to establish a new connection: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:168: NewConnectionError | |
During handling of the above exception, another exception occurred: | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f052aaf98> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f052aad30>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
> timeout=timeout | |
) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:449: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0737f9e8> | |
method = 'POST', url = '/seldon/test1/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.33230006388575206, 0.5496043072363148, 0.6785797578753154, 0.5777703956227764, 0.8826402545288229]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f052aad30> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0737fc88> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
chunked=chunked) | |
# If we're going to release the connection in ``finally:``, then | |
# the response doesn't need to know about the connection. Otherwise | |
# it will also try to release it and we'll have a double-release | |
# mess. | |
response_conn = conn if not release_conn else None | |
# Pass method to Response for length checking | |
response_kw['request_method'] = method | |
# Import httplib's response into our own wrapper object | |
response = self.ResponseCls.from_httplib(httplib_response, | |
pool=self, | |
connection=response_conn, | |
retries=retries, | |
**response_kw) | |
# Everything went great! | |
clean_exit = True | |
except queue.Empty: | |
# Timed out by queue. | |
raise EmptyPoolError(self, "No pool connections are available.") | |
except (TimeoutError, HTTPException, SocketError, ProtocolError, | |
BaseSSLError, SSLError, CertificateError) as e: | |
# Discard the connection for these exceptions. It will be | |
# replaced during the next _get_conn() call. | |
clean_exit = False | |
if isinstance(e, (BaseSSLError, CertificateError)): | |
e = SSLError(e) | |
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy: | |
e = ProxyError('Cannot connect to proxy.', e) | |
elif isinstance(e, (SocketError, HTTPException)): | |
e = ProtocolError('Connection aborted.', e) | |
retries = retries.increment(method, url, error=e, _pool=self, | |
> _stacktrace=sys.exc_info()[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:638: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
method = 'POST', url = '/seldon/test1/mymodel/api/v0.1/predictions' | |
response = None | |
error = NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8>: Failed to establish a new connection: [Errno 111] Connection refused') | |
_pool = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0737f9e8> | |
_stacktrace = <traceback object at 0x7f5f05277608> | |
def increment(self, method=None, url=None, response=None, error=None, | |
_pool=None, _stacktrace=None): | |
""" Return a new Retry object with incremented retry counters. | |
:param response: A response object, or None, if the server did not | |
return a response. | |
:type response: :class:`~urllib3.response.HTTPResponse` | |
:param Exception error: An error encountered during the request, or | |
None if the response was received successfully. | |
:return: A new ``Retry`` object. | |
""" | |
if self.total is False and error: | |
# Disabled, indicate to re-raise the error. | |
raise six.reraise(type(error), error, _stacktrace) | |
total = self.total | |
if total is not None: | |
total -= 1 | |
connect = self.connect | |
read = self.read | |
redirect = self.redirect | |
status_count = self.status | |
cause = 'unknown' | |
status = None | |
redirect_location = None | |
if error and self._is_connection_error(error): | |
# Connect retry? | |
if connect is False: | |
raise six.reraise(type(error), error, _stacktrace) | |
elif connect is not None: | |
connect -= 1 | |
elif error and self._is_read_error(error): | |
# Read retry? | |
if read is False or not self._is_method_retryable(method): | |
raise six.reraise(type(error), error, _stacktrace) | |
elif read is not None: | |
read -= 1 | |
elif response and response.get_redirect_location(): | |
# Redirect retry? | |
if redirect is not None: | |
redirect -= 1 | |
cause = 'too many redirects' | |
redirect_location = response.get_redirect_location() | |
status = response.status | |
else: | |
# Incrementing because of a server error like a 500 in | |
# status_forcelist and a the given method is in the whitelist | |
cause = ResponseError.GENERIC_ERROR | |
if response and response.status: | |
if status_count is not None: | |
status_count -= 1 | |
cause = ResponseError.SPECIFIC_ERROR.format( | |
status_code=response.status) | |
status = response.status | |
history = self.history + (RequestHistory(method, url, error, status, redirect_location),) | |
new_retry = self.new( | |
total=total, | |
connect=connect, read=read, redirect=redirect, status=status_count, | |
history=history) | |
if new_retry.is_exhausted(): | |
> raise MaxRetryError(_pool, url, error or ResponseError(cause)) | |
E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/test1/mymodel/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py:398: MaxRetryError | |
During handling of the above exception, another exception occurred: | |
self = <test_ksonnet_clusterwide.TestSingleNamespace object at 0x7f5f052aa1d0> | |
def test_single_model(self): | |
run('cd my-model && ks delete default && ks component rm mymodel', shell=True) | |
run('kubectl delete sdep --all', shell=True) | |
run('cd my-model && ks generate seldon-serve-simple-v1alpha2 mymodel --image seldonio/mock_classifier:1.0 --oauthKey=oauth-key --oauthSecret=oauth-secret && ks apply default -c mymodel', shell=True, check=True) | |
wait_for_rollout("mymodel-mymodel-025d03d") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret","test1",API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
> r = rest_request_ambassador("mymodel","test1",API_AMBASSADOR) | |
test_ksonnet_clusterwide.py:46: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:80: in rest_request_ambassador | |
json=payload) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:116: in post | |
return request('post', url, data=data, json=json, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:60: in request | |
return session.request(method=method, url=url, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:533: in request | |
resp = self.send(prep, **send_kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:646: in send | |
r = adapter.send(request, **kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f052aaf98> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f052aad30>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
timeout=timeout | |
) | |
# Send the request. | |
else: | |
if hasattr(conn, 'proxy_pool'): | |
conn = conn.proxy_pool | |
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) | |
try: | |
low_conn.putrequest(request.method, | |
url, | |
skip_accept_encoding=True) | |
for header, value in request.headers.items(): | |
low_conn.putheader(header, value) | |
low_conn.endheaders() | |
for i in request.body: | |
low_conn.send(hex(len(i))[2:].encode('utf-8')) | |
low_conn.send(b'\r\n') | |
low_conn.send(i) | |
low_conn.send(b'\r\n') | |
low_conn.send(b'0\r\n\r\n') | |
# Receive the response from the server | |
try: | |
# For Python 2.7, use buffering of HTTP responses | |
r = low_conn.getresponse(buffering=True) | |
except TypeError: | |
# For compatibility with Python 3.3+ | |
r = low_conn.getresponse() | |
resp = HTTPResponse.from_httplib( | |
r, | |
pool=conn, | |
connection=low_conn, | |
preload_content=False, | |
decode_content=False | |
) | |
except: | |
# If we hit any problems here, clean up the connection. | |
# Then, reraise so that we can handle the actual exception. | |
low_conn.close() | |
raise | |
except (ProtocolError, socket.error) as err: | |
raise ConnectionError(err, request=request) | |
except MaxRetryError as e: | |
if isinstance(e.reason, ConnectTimeoutError): | |
# TODO: Remove this in 3.0.0: see #2811 | |
if not isinstance(e.reason, NewConnectionError): | |
raise ConnectTimeout(e, request=request) | |
if isinstance(e.reason, ResponseError): | |
raise RetryError(e, request=request) | |
if isinstance(e.reason, _ProxyError): | |
raise ProxyError(e, request=request) | |
if isinstance(e.reason, _SSLError): | |
# This branch is for urllib3 v1.22 and later. | |
raise SSLError(e, request=request) | |
> raise ConnectionError(e, request=request) | |
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/test1/mymodel/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0737f2e8>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError | |
____________________ TestSingleNamespace.test_abtest_model _____________________ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
> (self._dns_host, self.port), self.timeout, **extra_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:159: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
sock.connect(sa) | |
return sock | |
except socket.error as e: | |
err = e | |
if sock is not None: | |
sock.close() | |
sock = None | |
if err is not None: | |
> raise err | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:80: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
> sock.connect(sa) | |
E ConnectionRefusedError: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:70: ConnectionRefusedError | |
During handling of the above exception, another exception occurred: | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0504af98> | |
method = 'POST', url = '/seldon/test1/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.9472754962993543, 0.6508667505506804, 0.15036740697981854, 0.6990594048419011]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0ef90438> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0504aa20> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
> chunked=chunked) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:600: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0504af98> | |
conn = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
method = 'POST', url = '/seldon/test1/myabtest/api/v0.1/predictions' | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0504aa20> | |
chunked = False | |
httplib_request_kw = {'body': b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.947275496299354...p, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'}} | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0504a470> | |
def _make_request(self, conn, method, url, timeout=_Default, chunked=False, | |
**httplib_request_kw): | |
""" | |
Perform a request on a given urllib connection object taken from our | |
pool. | |
:param conn: | |
a connection from one of our connection pools | |
:param timeout: | |
Socket timeout in seconds for the request. This can be a | |
float or integer, which will set the same timeout value for | |
the socket connect and the socket read, or an instance of | |
:class:`urllib3.util.Timeout`, which gives you more fine-grained | |
control over your timeouts. | |
""" | |
self.num_requests += 1 | |
timeout_obj = self._get_timeout(timeout) | |
timeout_obj.start_connect() | |
conn.timeout = timeout_obj.connect_timeout | |
# Trigger any extra validation we need to do. | |
try: | |
self._validate_conn(conn) | |
except (SocketTimeout, BaseSSLError) as e: | |
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout. | |
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) | |
raise | |
# conn.request() calls httplib.*.request, not the method in | |
# urllib3.request. It also calls makefile (recv) on the socket. | |
if chunked: | |
conn.request_chunked(method, url, **httplib_request_kw) | |
else: | |
> conn.request(method, url, **httplib_request_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:354: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
method = 'POST', url = '/seldon/test1/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.9472754962993543, 0.6508667505506804, 0.15036740697981854, 0.6990594048419011]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
def request(self, method, url, body=None, headers={}, *, | |
encode_chunked=False): | |
"""Send a complete request to the server.""" | |
> self._send_request(method, url, body, headers, encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1229: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
method = 'POST', url = '/seldon/test1/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.9472754962993543, 0.6508667505506804, 0.15036740697981854, 0.6990594048419011]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
encode_chunked = False | |
def _send_request(self, method, url, body, headers, encode_chunked): | |
# Honor explicitly requested Host: and Accept-Encoding: headers. | |
header_names = frozenset(k.lower() for k in headers) | |
skips = {} | |
if 'host' in header_names: | |
skips['skip_host'] = 1 | |
if 'accept-encoding' in header_names: | |
skips['skip_accept_encoding'] = 1 | |
self.putrequest(method, url, **skips) | |
# chunked encoding will happen if HTTP/1.1 is used and either | |
# the caller passes encode_chunked=True or the following | |
# conditions hold: | |
# 1. content-length has not been explicitly set | |
# 2. the body is a file or iterable, but not a str or bytes-like | |
# 3. Transfer-Encoding has NOT been explicitly set by the caller | |
if 'content-length' not in header_names: | |
# only chunk body if not explicitly set for backwards | |
# compatibility, assuming the client code is already handling the | |
# chunking | |
if 'transfer-encoding' not in header_names: | |
# if content-length cannot be automatically determined, fall | |
# back to chunked encoding | |
encode_chunked = False | |
content_length = self._get_content_length(body, method) | |
if content_length is None: | |
if body is not None: | |
if self.debuglevel > 0: | |
print('Unable to determine size of %r' % body) | |
encode_chunked = True | |
self.putheader('Transfer-Encoding', 'chunked') | |
else: | |
self.putheader('Content-Length', str(content_length)) | |
else: | |
encode_chunked = False | |
for hdr, value in headers.items(): | |
self.putheader(hdr, value) | |
if isinstance(body, str): | |
# RFC 2616 Section 3.7.1 says that text default has a | |
# default charset of iso-8859-1. | |
body = _encode(body, 'body') | |
> self.endheaders(body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1275: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.9472754962993543, 0.6508667505506804, 0.15036740697981854, 0.6990594048419011]}}}' | |
def endheaders(self, message_body=None, *, encode_chunked=False): | |
"""Indicate that the last header line has been sent to the server. | |
This method sends the request to the server. The optional message_body | |
argument can be used to pass a message body associated with the | |
request. | |
""" | |
if self.__state == _CS_REQ_STARTED: | |
self.__state = _CS_REQ_SENT | |
else: | |
raise CannotSendHeader() | |
> self._send_output(message_body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1224: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.9472754962993543, 0.6508667505506804, 0.15036740697981854, 0.6990594048419011]}}}' | |
encode_chunked = False | |
def _send_output(self, message_body=None, encode_chunked=False): | |
"""Send the currently buffered request and clear the buffer. | |
Appends an extra \\r\\n to the buffer. | |
A message_body may be specified, to be appended to the request. | |
""" | |
self._buffer.extend((b"", b"")) | |
msg = b"\r\n".join(self._buffer) | |
del self._buffer[:] | |
> self.send(msg) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1016: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
data = b'POST /seldon/test1/myabtest/api/v0.1/predictions HTTP/1.1\r\nHost: localhost:8003\r\nUser-Agent: python-requests/2.2...zip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 173\r\nContent-Type: application/json\r\n\r\n' | |
def send(self, data): | |
"""Send `data' to the server. | |
``data`` can be a string object, a bytes object, an array object, a | |
file-like object that supports a .read() method, or an iterable object. | |
""" | |
if self.sock is None: | |
if self.auto_open: | |
> self.connect() | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:956: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
def connect(self): | |
> conn = self._new_conn() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:181: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
(self._dns_host, self.port), self.timeout, **extra_kw) | |
except SocketTimeout as e: | |
raise ConnectTimeoutError( | |
self, "Connection to %s timed out. (connect timeout=%s)" % | |
(self.host, self.timeout)) | |
except SocketError as e: | |
raise NewConnectionError( | |
> self, "Failed to establish a new connection: %s" % e) | |
E urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5f0504aef0>: Failed to establish a new connection: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:168: NewConnectionError | |
During handling of the above exception, another exception occurred: | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f0ef90ef0> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0ef90438>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
> timeout=timeout | |
) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:449: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0504af98> | |
method = 'POST', url = '/seldon/test1/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7026188932350869, 0.9472754962993543, 0.6508667505506804, 0.15036740697981854, 0.6990594048419011]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0ef90438> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0504aa20> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
chunked=chunked) | |
# If we're going to release the connection in ``finally:``, then | |
# the response doesn't need to know about the connection. Otherwise | |
# it will also try to release it and we'll have a double-release | |
# mess. | |
response_conn = conn if not release_conn else None | |
# Pass method to Response for length checking | |
response_kw['request_method'] = method | |
# Import httplib's response into our own wrapper object | |
response = self.ResponseCls.from_httplib(httplib_response, | |
pool=self, | |
connection=response_conn, | |
retries=retries, | |
**response_kw) | |
# Everything went great! | |
clean_exit = True | |
except queue.Empty: | |
# Timed out by queue. | |
raise EmptyPoolError(self, "No pool connections are available.") | |
except (TimeoutError, HTTPException, SocketError, ProtocolError, | |
BaseSSLError, SSLError, CertificateError) as e: | |
# Discard the connection for these exceptions. It will be | |
# replaced during the next _get_conn() call. | |
clean_exit = False | |
if isinstance(e, (BaseSSLError, CertificateError)): | |
e = SSLError(e) | |
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy: | |
e = ProxyError('Cannot connect to proxy.', e) | |
elif isinstance(e, (SocketError, HTTPException)): | |
e = ProtocolError('Connection aborted.', e) | |
retries = retries.increment(method, url, error=e, _pool=self, | |
> _stacktrace=sys.exc_info()[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:638: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
method = 'POST', url = '/seldon/test1/myabtest/api/v0.1/predictions' | |
response = None | |
error = NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0504aef0>: Failed to establish a new connection: [Errno 111] Connection refused') | |
_pool = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0504af98> | |
_stacktrace = <traceback object at 0x7f5f07390688> | |
def increment(self, method=None, url=None, response=None, error=None, | |
_pool=None, _stacktrace=None): | |
""" Return a new Retry object with incremented retry counters. | |
:param response: A response object, or None, if the server did not | |
return a response. | |
:type response: :class:`~urllib3.response.HTTPResponse` | |
:param Exception error: An error encountered during the request, or | |
None if the response was received successfully. | |
:return: A new ``Retry`` object. | |
""" | |
if self.total is False and error: | |
# Disabled, indicate to re-raise the error. | |
raise six.reraise(type(error), error, _stacktrace) | |
total = self.total | |
if total is not None: | |
total -= 1 | |
connect = self.connect | |
read = self.read | |
redirect = self.redirect | |
status_count = self.status | |
cause = 'unknown' | |
status = None | |
redirect_location = None | |
if error and self._is_connection_error(error): | |
# Connect retry? | |
if connect is False: | |
raise six.reraise(type(error), error, _stacktrace) | |
elif connect is not None: | |
connect -= 1 | |
elif error and self._is_read_error(error): | |
# Read retry? | |
if read is False or not self._is_method_retryable(method): | |
raise six.reraise(type(error), error, _stacktrace) | |
elif read is not None: | |
read -= 1 | |
elif response and response.get_redirect_location(): | |
# Redirect retry? | |
if redirect is not None: | |
redirect -= 1 | |
cause = 'too many redirects' | |
redirect_location = response.get_redirect_location() | |
status = response.status | |
else: | |
# Incrementing because of a server error like a 500 in | |
# status_forcelist and a the given method is in the whitelist | |
cause = ResponseError.GENERIC_ERROR | |
if response and response.status: | |
if status_count is not None: | |
status_count -= 1 | |
cause = ResponseError.SPECIFIC_ERROR.format( | |
status_code=response.status) | |
status = response.status | |
history = self.history + (RequestHistory(method, url, error, status, redirect_location),) | |
new_retry = self.new( | |
total=total, | |
connect=connect, read=read, redirect=redirect, status=status_count, | |
history=history) | |
if new_retry.is_exhausted(): | |
> raise MaxRetryError(_pool, url, error or ResponseError(cause)) | |
E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/test1/myabtest/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0504aef0>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py:398: MaxRetryError | |
During handling of the above exception, another exception occurred: | |
self = <test_ksonnet_clusterwide.TestSingleNamespace object at 0x7f5f0504a828> | |
def test_abtest_model(self): | |
run('cd my-model && ks delete default && ks component rm mymodel', shell=True) | |
run('kubectl delete sdep --all', shell=True) | |
run('cd my-model && ks generate seldon-abtest-v1alpha2 myabtest --imageA seldonio/mock_classifier:1.0 --imageB seldonio/mock_classifier:1.0 --oauthKey=oauth-key --oauthSecret=oauth-secret && ks apply default -c myabtest', shell=True) | |
wait_for_rollout("myabtest-myabtest-41de5b8") | |
wait_for_rollout("myabtest-myabtest-df66c5c") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret","test1",API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
> r = rest_request_ambassador("myabtest","test1",API_AMBASSADOR) | |
test_ksonnet_clusterwide.py:70: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:80: in rest_request_ambassador | |
json=payload) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:116: in post | |
return request('post', url, data=data, json=json, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:60: in request | |
return session.request(method=method, url=url, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:533: in request | |
resp = self.send(prep, **send_kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:646: in send | |
r = adapter.send(request, **kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f0ef90ef0> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0ef90438>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
timeout=timeout | |
) | |
# Send the request. | |
else: | |
if hasattr(conn, 'proxy_pool'): | |
conn = conn.proxy_pool | |
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) | |
try: | |
low_conn.putrequest(request.method, | |
url, | |
skip_accept_encoding=True) | |
for header, value in request.headers.items(): | |
low_conn.putheader(header, value) | |
low_conn.endheaders() | |
for i in request.body: | |
low_conn.send(hex(len(i))[2:].encode('utf-8')) | |
low_conn.send(b'\r\n') | |
low_conn.send(i) | |
low_conn.send(b'\r\n') | |
low_conn.send(b'0\r\n\r\n') | |
# Receive the response from the server | |
try: | |
# For Python 2.7, use buffering of HTTP responses | |
r = low_conn.getresponse(buffering=True) | |
except TypeError: | |
# For compatibility with Python 3.3+ | |
r = low_conn.getresponse() | |
resp = HTTPResponse.from_httplib( | |
r, | |
pool=conn, | |
connection=low_conn, | |
preload_content=False, | |
decode_content=False | |
) | |
except: | |
# If we hit any problems here, clean up the connection. | |
# Then, reraise so that we can handle the actual exception. | |
low_conn.close() | |
raise | |
except (ProtocolError, socket.error) as err: | |
raise ConnectionError(err, request=request) | |
except MaxRetryError as e: | |
if isinstance(e.reason, ConnectTimeoutError): | |
# TODO: Remove this in 3.0.0: see #2811 | |
if not isinstance(e.reason, NewConnectionError): | |
raise ConnectTimeout(e, request=request) | |
if isinstance(e.reason, ResponseError): | |
raise RetryError(e, request=request) | |
if isinstance(e.reason, _ProxyError): | |
raise ProxyError(e, request=request) | |
if isinstance(e.reason, _SSLError): | |
# This branch is for urllib3 v1.22 and later. | |
raise SSLError(e, request=request) | |
> raise ConnectionError(e, request=request) | |
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/test1/myabtest/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0504aef0>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError | |
______________________ TestSingleNamespace.test_mab_model ______________________ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
> (self._dns_host, self.port), self.timeout, **extra_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:159: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
sock.connect(sa) | |
return sock | |
except socket.error as e: | |
err = e | |
if sock is not None: | |
sock.close() | |
sock = None | |
if err is not None: | |
> raise err | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:80: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
> sock.connect(sa) | |
E ConnectionRefusedError: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:70: ConnectionRefusedError | |
During handling of the above exception, another exception occurred: | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f04eed438> | |
method = 'POST', url = '/seldon/test1/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.3394924258937342, 0.9532563562486398, 0.9824232133095533, 0.22589841203484662]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '174', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f050d91d0> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f04eed5c0> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
> chunked=chunked) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:600: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f04eed438> | |
conn = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
method = 'POST', url = '/seldon/test1/mymab/api/v0.1/predictions' | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f04eed5c0> | |
chunked = False | |
httplib_request_kw = {'body': b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.33949242589373...p, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '174', 'Content-Type': 'application/json'}} | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f04eed550> | |
def _make_request(self, conn, method, url, timeout=_Default, chunked=False, | |
**httplib_request_kw): | |
""" | |
Perform a request on a given urllib connection object taken from our | |
pool. | |
:param conn: | |
a connection from one of our connection pools | |
:param timeout: | |
Socket timeout in seconds for the request. This can be a | |
float or integer, which will set the same timeout value for | |
the socket connect and the socket read, or an instance of | |
:class:`urllib3.util.Timeout`, which gives you more fine-grained | |
control over your timeouts. | |
""" | |
self.num_requests += 1 | |
timeout_obj = self._get_timeout(timeout) | |
timeout_obj.start_connect() | |
conn.timeout = timeout_obj.connect_timeout | |
# Trigger any extra validation we need to do. | |
try: | |
self._validate_conn(conn) | |
except (SocketTimeout, BaseSSLError) as e: | |
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout. | |
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) | |
raise | |
# conn.request() calls httplib.*.request, not the method in | |
# urllib3.request. It also calls makefile (recv) on the socket. | |
if chunked: | |
conn.request_chunked(method, url, **httplib_request_kw) | |
else: | |
> conn.request(method, url, **httplib_request_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:354: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
method = 'POST', url = '/seldon/test1/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.3394924258937342, 0.9532563562486398, 0.9824232133095533, 0.22589841203484662]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '174', 'Content-Type': 'application/json'} | |
def request(self, method, url, body=None, headers={}, *, | |
encode_chunked=False): | |
"""Send a complete request to the server.""" | |
> self._send_request(method, url, body, headers, encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1229: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
method = 'POST', url = '/seldon/test1/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.3394924258937342, 0.9532563562486398, 0.9824232133095533, 0.22589841203484662]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '174', 'Content-Type': 'application/json'} | |
encode_chunked = False | |
def _send_request(self, method, url, body, headers, encode_chunked): | |
# Honor explicitly requested Host: and Accept-Encoding: headers. | |
header_names = frozenset(k.lower() for k in headers) | |
skips = {} | |
if 'host' in header_names: | |
skips['skip_host'] = 1 | |
if 'accept-encoding' in header_names: | |
skips['skip_accept_encoding'] = 1 | |
self.putrequest(method, url, **skips) | |
# chunked encoding will happen if HTTP/1.1 is used and either | |
# the caller passes encode_chunked=True or the following | |
# conditions hold: | |
# 1. content-length has not been explicitly set | |
# 2. the body is a file or iterable, but not a str or bytes-like | |
# 3. Transfer-Encoding has NOT been explicitly set by the caller | |
if 'content-length' not in header_names: | |
# only chunk body if not explicitly set for backwards | |
# compatibility, assuming the client code is already handling the | |
# chunking | |
if 'transfer-encoding' not in header_names: | |
# if content-length cannot be automatically determined, fall | |
# back to chunked encoding | |
encode_chunked = False | |
content_length = self._get_content_length(body, method) | |
if content_length is None: | |
if body is not None: | |
if self.debuglevel > 0: | |
print('Unable to determine size of %r' % body) | |
encode_chunked = True | |
self.putheader('Transfer-Encoding', 'chunked') | |
else: | |
self.putheader('Content-Length', str(content_length)) | |
else: | |
encode_chunked = False | |
for hdr, value in headers.items(): | |
self.putheader(hdr, value) | |
if isinstance(body, str): | |
# RFC 2616 Section 3.7.1 says that text default has a | |
# default charset of iso-8859-1. | |
body = _encode(body, 'body') | |
> self.endheaders(body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1275: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.3394924258937342, 0.9532563562486398, 0.9824232133095533, 0.22589841203484662]}}}' | |
def endheaders(self, message_body=None, *, encode_chunked=False): | |
"""Indicate that the last header line has been sent to the server. | |
This method sends the request to the server. The optional message_body | |
argument can be used to pass a message body associated with the | |
request. | |
""" | |
if self.__state == _CS_REQ_STARTED: | |
self.__state = _CS_REQ_SENT | |
else: | |
raise CannotSendHeader() | |
> self._send_output(message_body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1224: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.3394924258937342, 0.9532563562486398, 0.9824232133095533, 0.22589841203484662]}}}' | |
encode_chunked = False | |
def _send_output(self, message_body=None, encode_chunked=False): | |
"""Send the currently buffered request and clear the buffer. | |
Appends an extra \\r\\n to the buffer. | |
A message_body may be specified, to be appended to the request. | |
""" | |
self._buffer.extend((b"", b"")) | |
msg = b"\r\n".join(self._buffer) | |
del self._buffer[:] | |
> self.send(msg) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1016: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
data = b'POST /seldon/test1/mymab/api/v0.1/predictions HTTP/1.1\r\nHost: localhost:8003\r\nUser-Agent: python-requests/2.21.0...zip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 174\r\nContent-Type: application/json\r\n\r\n' | |
def send(self, data): | |
"""Send `data' to the server. | |
``data`` can be a string object, a bytes object, an array object, a | |
file-like object that supports a .read() method, or an iterable object. | |
""" | |
if self.sock is None: | |
if self.auto_open: | |
> self.connect() | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:956: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
def connect(self): | |
> conn = self._new_conn() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:181: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f04eed278> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
(self._dns_host, self.port), self.timeout, **extra_kw) | |
except SocketTimeout as e: | |
raise ConnectTimeoutError( | |
self, "Connection to %s timed out. (connect timeout=%s)" % | |
(self.host, self.timeout)) | |
except SocketError as e: | |
raise NewConnectionError( | |
> self, "Failed to establish a new connection: %s" % e) | |
E urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5f04eed278>: Failed to establish a new connection: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:168: NewConnectionError | |
During handling of the above exception, another exception occurred: | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f050d9940> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f050d91d0>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
> timeout=timeout | |
) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:449: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f04eed438> | |
method = 'POST', url = '/seldon/test1/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.39097736511238246, 0.3394924258937342, 0.9532563562486398, 0.9824232133095533, 0.22589841203484662]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '174', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f050d91d0> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f04eed5c0> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
chunked=chunked) | |
# If we're going to release the connection in ``finally:``, then | |
# the response doesn't need to know about the connection. Otherwise | |
# it will also try to release it and we'll have a double-release | |
# mess. | |
response_conn = conn if not release_conn else None | |
# Pass method to Response for length checking | |
response_kw['request_method'] = method | |
# Import httplib's response into our own wrapper object | |
response = self.ResponseCls.from_httplib(httplib_response, | |
pool=self, | |
connection=response_conn, | |
retries=retries, | |
**response_kw) | |
# Everything went great! | |
clean_exit = True | |
except queue.Empty: | |
# Timed out by queue. | |
raise EmptyPoolError(self, "No pool connections are available.") | |
except (TimeoutError, HTTPException, SocketError, ProtocolError, | |
BaseSSLError, SSLError, CertificateError) as e: | |
# Discard the connection for these exceptions. It will be | |
# replaced during the next _get_conn() call. | |
clean_exit = False | |
if isinstance(e, (BaseSSLError, CertificateError)): | |
e = SSLError(e) | |
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy: | |
e = ProxyError('Cannot connect to proxy.', e) | |
elif isinstance(e, (SocketError, HTTPException)): | |
e = ProtocolError('Connection aborted.', e) | |
retries = retries.increment(method, url, error=e, _pool=self, | |
> _stacktrace=sys.exc_info()[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:638: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
method = 'POST', url = '/seldon/test1/mymab/api/v0.1/predictions' | |
response = None | |
error = NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f04eed278>: Failed to establish a new connection: [Errno 111] Connection refused') | |
_pool = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f04eed438> | |
_stacktrace = <traceback object at 0x7f5f04ff7208> | |
def increment(self, method=None, url=None, response=None, error=None, | |
_pool=None, _stacktrace=None): | |
""" Return a new Retry object with incremented retry counters. | |
:param response: A response object, or None, if the server did not | |
return a response. | |
:type response: :class:`~urllib3.response.HTTPResponse` | |
:param Exception error: An error encountered during the request, or | |
None if the response was received successfully. | |
:return: A new ``Retry`` object. | |
""" | |
if self.total is False and error: | |
# Disabled, indicate to re-raise the error. | |
raise six.reraise(type(error), error, _stacktrace) | |
total = self.total | |
if total is not None: | |
total -= 1 | |
connect = self.connect | |
read = self.read | |
redirect = self.redirect | |
status_count = self.status | |
cause = 'unknown' | |
status = None | |
redirect_location = None | |
if error and self._is_connection_error(error): | |
# Connect retry? | |
if connect is False: | |
raise six.reraise(type(error), error, _stacktrace) | |
elif connect is not None: | |
connect -= 1 | |
elif error and self._is_read_error(error): | |
# Read retry? | |
if read is False or not self._is_method_retryable(method): | |
raise six.reraise(type(error), error, _stacktrace) | |
elif read is not None: | |
read -= 1 | |
elif response and response.get_redirect_location(): | |
# Redirect retry? | |
if redirect is not None: | |
redirect -= 1 | |
cause = 'too many redirects' | |
redirect_location = response.get_redirect_location() | |
status = response.status | |
else: | |
# Incrementing because of a server error like a 500 in | |
# status_forcelist and a the given method is in the whitelist | |
cause = ResponseError.GENERIC_ERROR | |
if response and response.status: | |
if status_count is not None: | |
status_count -= 1 | |
cause = ResponseError.SPECIFIC_ERROR.format( | |
status_code=response.status) | |
status = response.status | |
history = self.history + (RequestHistory(method, url, error, status, redirect_location),) | |
new_retry = self.new( | |
total=total, | |
connect=connect, read=read, redirect=redirect, status=status_count, | |
history=history) | |
if new_retry.is_exhausted(): | |
> raise MaxRetryError(_pool, url, error or ResponseError(cause)) | |
E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/test1/mymab/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f04eed278>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py:398: MaxRetryError | |
During handling of the above exception, another exception occurred: | |
self = <test_ksonnet_clusterwide.TestSingleNamespace object at 0x7f5f04eed2b0> | |
def test_mab_model(self): | |
run('cd my-model && ks delete default && ks component rm mymab', shell=True) | |
run('kubectl delete sdep --all', shell=True) | |
run('cd my-model && ks generate seldon-mab-v1alpha2 mymab --imageA seldonio/mock_classifier:1.0 --imageB seldonio/mock_classifier:1.0 --oauthKey=oauth-key --oauthSecret=oauth-secret && ks apply default -c mymab', shell=True) | |
wait_for_rollout("mymab-mymab-41de5b8") | |
wait_for_rollout("mymab-mymab-b8038b2") | |
wait_for_rollout("mymab-mymab-df66c5c") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret","test1",API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
> r = rest_request_ambassador("mymab","test1",API_AMBASSADOR) | |
test_ksonnet_clusterwide.py:95: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:80: in rest_request_ambassador | |
json=payload) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:116: in post | |
return request('post', url, data=data, json=json, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:60: in request | |
return session.request(method=method, url=url, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:533: in request | |
resp = self.send(prep, **send_kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:646: in send | |
r = adapter.send(request, **kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f050d9940> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f050d91d0>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
timeout=timeout | |
) | |
# Send the request. | |
else: | |
if hasattr(conn, 'proxy_pool'): | |
conn = conn.proxy_pool | |
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) | |
try: | |
low_conn.putrequest(request.method, | |
url, | |
skip_accept_encoding=True) | |
for header, value in request.headers.items(): | |
low_conn.putheader(header, value) | |
low_conn.endheaders() | |
for i in request.body: | |
low_conn.send(hex(len(i))[2:].encode('utf-8')) | |
low_conn.send(b'\r\n') | |
low_conn.send(i) | |
low_conn.send(b'\r\n') | |
low_conn.send(b'0\r\n\r\n') | |
# Receive the response from the server | |
try: | |
# For Python 2.7, use buffering of HTTP responses | |
r = low_conn.getresponse(buffering=True) | |
except TypeError: | |
# For compatibility with Python 3.3+ | |
r = low_conn.getresponse() | |
resp = HTTPResponse.from_httplib( | |
r, | |
pool=conn, | |
connection=low_conn, | |
preload_content=False, | |
decode_content=False | |
) | |
except: | |
# If we hit any problems here, clean up the connection. | |
# Then, reraise so that we can handle the actual exception. | |
low_conn.close() | |
raise | |
except (ProtocolError, socket.error) as err: | |
raise ConnectionError(err, request=request) | |
except MaxRetryError as e: | |
if isinstance(e.reason, ConnectTimeoutError): | |
# TODO: Remove this in 3.0.0: see #2811 | |
if not isinstance(e.reason, NewConnectionError): | |
raise ConnectTimeout(e, request=request) | |
if isinstance(e.reason, ResponseError): | |
raise RetryError(e, request=request) | |
if isinstance(e.reason, _ProxyError): | |
raise ProxyError(e, request=request) | |
if isinstance(e.reason, _SSLError): | |
# This branch is for urllib3 v1.22 and later. | |
raise SSLError(e, request=request) | |
> raise ConnectionError(e, request=request) | |
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/test1/mymab/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f04eed278>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError | |
____________________ TestSingleNamespace.test_single_model _____________________ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
> (self._dns_host, self.port), self.timeout, **extra_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:159: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
sock.connect(sa) | |
return sock | |
except socket.error as e: | |
err = e | |
if sock is not None: | |
sock.close() | |
sock = None | |
if err is not None: | |
> raise err | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:80: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
> sock.connect(sa) | |
E ConnectionRefusedError: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:70: ConnectionRefusedError | |
During handling of the above exception, another exception occurred: | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f051e8128> | |
method = 'POST', url = '/seldon/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.4876125541810421, 0.0034279367458729393, 0.8070442193106835, 0.7351833165799191]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '175', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f051e8588> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f051e8518> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
> chunked=chunked) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:600: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f051e8128> | |
conn = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
method = 'POST', url = '/seldon/mymodel/api/v0.1/predictions' | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f051e8518> | |
chunked = False | |
httplib_request_kw = {'body': b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.487612554181042...p, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '175', 'Content-Type': 'application/json'}} | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f051e8390> | |
def _make_request(self, conn, method, url, timeout=_Default, chunked=False, | |
**httplib_request_kw): | |
""" | |
Perform a request on a given urllib connection object taken from our | |
pool. | |
:param conn: | |
a connection from one of our connection pools | |
:param timeout: | |
Socket timeout in seconds for the request. This can be a | |
float or integer, which will set the same timeout value for | |
the socket connect and the socket read, or an instance of | |
:class:`urllib3.util.Timeout`, which gives you more fine-grained | |
control over your timeouts. | |
""" | |
self.num_requests += 1 | |
timeout_obj = self._get_timeout(timeout) | |
timeout_obj.start_connect() | |
conn.timeout = timeout_obj.connect_timeout | |
# Trigger any extra validation we need to do. | |
try: | |
self._validate_conn(conn) | |
except (SocketTimeout, BaseSSLError) as e: | |
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout. | |
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) | |
raise | |
# conn.request() calls httplib.*.request, not the method in | |
# urllib3.request. It also calls makefile (recv) on the socket. | |
if chunked: | |
conn.request_chunked(method, url, **httplib_request_kw) | |
else: | |
> conn.request(method, url, **httplib_request_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:354: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
method = 'POST', url = '/seldon/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.4876125541810421, 0.0034279367458729393, 0.8070442193106835, 0.7351833165799191]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '175', 'Content-Type': 'application/json'} | |
def request(self, method, url, body=None, headers={}, *, | |
encode_chunked=False): | |
"""Send a complete request to the server.""" | |
> self._send_request(method, url, body, headers, encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1229: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
method = 'POST', url = '/seldon/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.4876125541810421, 0.0034279367458729393, 0.8070442193106835, 0.7351833165799191]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '175', 'Content-Type': 'application/json'} | |
encode_chunked = False | |
def _send_request(self, method, url, body, headers, encode_chunked): | |
# Honor explicitly requested Host: and Accept-Encoding: headers. | |
header_names = frozenset(k.lower() for k in headers) | |
skips = {} | |
if 'host' in header_names: | |
skips['skip_host'] = 1 | |
if 'accept-encoding' in header_names: | |
skips['skip_accept_encoding'] = 1 | |
self.putrequest(method, url, **skips) | |
# chunked encoding will happen if HTTP/1.1 is used and either | |
# the caller passes encode_chunked=True or the following | |
# conditions hold: | |
# 1. content-length has not been explicitly set | |
# 2. the body is a file or iterable, but not a str or bytes-like | |
# 3. Transfer-Encoding has NOT been explicitly set by the caller | |
if 'content-length' not in header_names: | |
# only chunk body if not explicitly set for backwards | |
# compatibility, assuming the client code is already handling the | |
# chunking | |
if 'transfer-encoding' not in header_names: | |
# if content-length cannot be automatically determined, fall | |
# back to chunked encoding | |
encode_chunked = False | |
content_length = self._get_content_length(body, method) | |
if content_length is None: | |
if body is not None: | |
if self.debuglevel > 0: | |
print('Unable to determine size of %r' % body) | |
encode_chunked = True | |
self.putheader('Transfer-Encoding', 'chunked') | |
else: | |
self.putheader('Content-Length', str(content_length)) | |
else: | |
encode_chunked = False | |
for hdr, value in headers.items(): | |
self.putheader(hdr, value) | |
if isinstance(body, str): | |
# RFC 2616 Section 3.7.1 says that text default has a | |
# default charset of iso-8859-1. | |
body = _encode(body, 'body') | |
> self.endheaders(body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1275: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.4876125541810421, 0.0034279367458729393, 0.8070442193106835, 0.7351833165799191]}}}' | |
def endheaders(self, message_body=None, *, encode_chunked=False): | |
"""Indicate that the last header line has been sent to the server. | |
This method sends the request to the server. The optional message_body | |
argument can be used to pass a message body associated with the | |
request. | |
""" | |
if self.__state == _CS_REQ_STARTED: | |
self.__state = _CS_REQ_SENT | |
else: | |
raise CannotSendHeader() | |
> self._send_output(message_body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1224: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.4876125541810421, 0.0034279367458729393, 0.8070442193106835, 0.7351833165799191]}}}' | |
encode_chunked = False | |
def _send_output(self, message_body=None, encode_chunked=False): | |
"""Send the currently buffered request and clear the buffer. | |
Appends an extra \\r\\n to the buffer. | |
A message_body may be specified, to be appended to the request. | |
""" | |
self._buffer.extend((b"", b"")) | |
msg = b"\r\n".join(self._buffer) | |
del self._buffer[:] | |
> self.send(msg) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1016: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
data = b'POST /seldon/mymodel/api/v0.1/predictions HTTP/1.1\r\nHost: localhost:8003\r\nUser-Agent: python-requests/2.21.0\r\n...zip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 175\r\nContent-Type: application/json\r\n\r\n' | |
def send(self, data): | |
"""Send `data' to the server. | |
``data`` can be a string object, a bytes object, an array object, a | |
file-like object that supports a .read() method, or an iterable object. | |
""" | |
if self.sock is None: | |
if self.auto_open: | |
> self.connect() | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:956: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
def connect(self): | |
> conn = self._new_conn() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:181: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f051e8278> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
(self._dns_host, self.port), self.timeout, **extra_kw) | |
except SocketTimeout as e: | |
raise ConnectTimeoutError( | |
self, "Connection to %s timed out. (connect timeout=%s)" % | |
(self.host, self.timeout)) | |
except SocketError as e: | |
raise NewConnectionError( | |
> self, "Failed to establish a new connection: %s" % e) | |
E urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5f051e8278>: Failed to establish a new connection: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:168: NewConnectionError | |
During handling of the above exception, another exception occurred: | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f04f57780> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f051e8588>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
> timeout=timeout | |
) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:449: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f051e8128> | |
method = 'POST', url = '/seldon/mymodel/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7239419022327515, 0.4876125541810421, 0.0034279367458729393, 0.8070442193106835, 0.7351833165799191]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '175', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f051e8588> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f051e8518> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
chunked=chunked) | |
# If we're going to release the connection in ``finally:``, then | |
# the response doesn't need to know about the connection. Otherwise | |
# it will also try to release it and we'll have a double-release | |
# mess. | |
response_conn = conn if not release_conn else None | |
# Pass method to Response for length checking | |
response_kw['request_method'] = method | |
# Import httplib's response into our own wrapper object | |
response = self.ResponseCls.from_httplib(httplib_response, | |
pool=self, | |
connection=response_conn, | |
retries=retries, | |
**response_kw) | |
# Everything went great! | |
clean_exit = True | |
except queue.Empty: | |
# Timed out by queue. | |
raise EmptyPoolError(self, "No pool connections are available.") | |
except (TimeoutError, HTTPException, SocketError, ProtocolError, | |
BaseSSLError, SSLError, CertificateError) as e: | |
# Discard the connection for these exceptions. It will be | |
# replaced during the next _get_conn() call. | |
clean_exit = False | |
if isinstance(e, (BaseSSLError, CertificateError)): | |
e = SSLError(e) | |
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy: | |
e = ProxyError('Cannot connect to proxy.', e) | |
elif isinstance(e, (SocketError, HTTPException)): | |
e = ProtocolError('Connection aborted.', e) | |
retries = retries.increment(method, url, error=e, _pool=self, | |
> _stacktrace=sys.exc_info()[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:638: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
method = 'POST', url = '/seldon/mymodel/api/v0.1/predictions', response = None | |
error = NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f051e8278>: Failed to establish a new connection: [Errno 111] Connection refused') | |
_pool = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f051e8128> | |
_stacktrace = <traceback object at 0x7f5f05203bc8> | |
def increment(self, method=None, url=None, response=None, error=None, | |
_pool=None, _stacktrace=None): | |
""" Return a new Retry object with incremented retry counters. | |
:param response: A response object, or None, if the server did not | |
return a response. | |
:type response: :class:`~urllib3.response.HTTPResponse` | |
:param Exception error: An error encountered during the request, or | |
None if the response was received successfully. | |
:return: A new ``Retry`` object. | |
""" | |
if self.total is False and error: | |
# Disabled, indicate to re-raise the error. | |
raise six.reraise(type(error), error, _stacktrace) | |
total = self.total | |
if total is not None: | |
total -= 1 | |
connect = self.connect | |
read = self.read | |
redirect = self.redirect | |
status_count = self.status | |
cause = 'unknown' | |
status = None | |
redirect_location = None | |
if error and self._is_connection_error(error): | |
# Connect retry? | |
if connect is False: | |
raise six.reraise(type(error), error, _stacktrace) | |
elif connect is not None: | |
connect -= 1 | |
elif error and self._is_read_error(error): | |
# Read retry? | |
if read is False or not self._is_method_retryable(method): | |
raise six.reraise(type(error), error, _stacktrace) | |
elif read is not None: | |
read -= 1 | |
elif response and response.get_redirect_location(): | |
# Redirect retry? | |
if redirect is not None: | |
redirect -= 1 | |
cause = 'too many redirects' | |
redirect_location = response.get_redirect_location() | |
status = response.status | |
else: | |
# Incrementing because of a server error like a 500 in | |
# status_forcelist and a the given method is in the whitelist | |
cause = ResponseError.GENERIC_ERROR | |
if response and response.status: | |
if status_count is not None: | |
status_count -= 1 | |
cause = ResponseError.SPECIFIC_ERROR.format( | |
status_code=response.status) | |
status = response.status | |
history = self.history + (RequestHistory(method, url, error, status, redirect_location),) | |
new_retry = self.new( | |
total=total, | |
connect=connect, read=read, redirect=redirect, status=status_count, | |
history=history) | |
if new_retry.is_exhausted(): | |
> raise MaxRetryError(_pool, url, error or ResponseError(cause)) | |
E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/mymodel/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f051e8278>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py:398: MaxRetryError | |
During handling of the above exception, another exception occurred: | |
self = <test_ksonnet_single_namespace.TestSingleNamespace object at 0x7f5f04f579b0> | |
def test_single_model(self): | |
run('cd my-model && ks delete default && ks component rm mymodel', shell=True) | |
run('kubectl delete sdep --all', shell=True) | |
run('cd my-model && ks generate seldon-serve-simple-v1alpha2 mymodel --image seldonio/mock_classifier:1.0 --oauthKey=oauth-key --oauthSecret=oauth-secret && ks apply default -c mymodel', shell=True, check=True) | |
wait_for_rollout("mymodel-mymodel-025d03d") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret",None,API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
> r = rest_request_ambassador("mymodel",None,API_AMBASSADOR) | |
test_ksonnet_single_namespace.py:46: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:76: in rest_request_ambassador | |
json=payload) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:116: in post | |
return request('post', url, data=data, json=json, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:60: in request | |
return session.request(method=method, url=url, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:533: in request | |
resp = self.send(prep, **send_kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:646: in send | |
r = adapter.send(request, **kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f04f57780> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f051e8588>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
timeout=timeout | |
) | |
# Send the request. | |
else: | |
if hasattr(conn, 'proxy_pool'): | |
conn = conn.proxy_pool | |
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) | |
try: | |
low_conn.putrequest(request.method, | |
url, | |
skip_accept_encoding=True) | |
for header, value in request.headers.items(): | |
low_conn.putheader(header, value) | |
low_conn.endheaders() | |
for i in request.body: | |
low_conn.send(hex(len(i))[2:].encode('utf-8')) | |
low_conn.send(b'\r\n') | |
low_conn.send(i) | |
low_conn.send(b'\r\n') | |
low_conn.send(b'0\r\n\r\n') | |
# Receive the response from the server | |
try: | |
# For Python 2.7, use buffering of HTTP responses | |
r = low_conn.getresponse(buffering=True) | |
except TypeError: | |
# For compatibility with Python 3.3+ | |
r = low_conn.getresponse() | |
resp = HTTPResponse.from_httplib( | |
r, | |
pool=conn, | |
connection=low_conn, | |
preload_content=False, | |
decode_content=False | |
) | |
except: | |
# If we hit any problems here, clean up the connection. | |
# Then, reraise so that we can handle the actual exception. | |
low_conn.close() | |
raise | |
except (ProtocolError, socket.error) as err: | |
raise ConnectionError(err, request=request) | |
except MaxRetryError as e: | |
if isinstance(e.reason, ConnectTimeoutError): | |
# TODO: Remove this in 3.0.0: see #2811 | |
if not isinstance(e.reason, NewConnectionError): | |
raise ConnectTimeout(e, request=request) | |
if isinstance(e.reason, ResponseError): | |
raise RetryError(e, request=request) | |
if isinstance(e.reason, _ProxyError): | |
raise ProxyError(e, request=request) | |
if isinstance(e.reason, _SSLError): | |
# This branch is for urllib3 v1.22 and later. | |
raise SSLError(e, request=request) | |
> raise ConnectionError(e, request=request) | |
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/mymodel/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f051e8278>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError | |
____________________ TestSingleNamespace.test_abtest_model _____________________ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
> (self._dns_host, self.port), self.timeout, **extra_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:159: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
sock.connect(sa) | |
return sock | |
except socket.error as e: | |
err = e | |
if sock is not None: | |
sock.close() | |
sock = None | |
if err is not None: | |
> raise err | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:80: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
> sock.connect(sa) | |
E ConnectionRefusedError: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:70: ConnectionRefusedError | |
During handling of the above exception, another exception occurred: | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f05127b70> | |
method = 'POST', url = '/seldon/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.9404752763052208, 0.961519255562848, 0.46092393059667414, 0.6530442627920168]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '172', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f05127860> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f051273c8> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
> chunked=chunked) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:600: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f05127b70> | |
conn = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
method = 'POST', url = '/seldon/myabtest/api/v0.1/predictions' | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f051273c8> | |
chunked = False | |
httplib_request_kw = {'body': b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.940475276305220...p, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '172', 'Content-Type': 'application/json'}} | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f05127940> | |
def _make_request(self, conn, method, url, timeout=_Default, chunked=False, | |
**httplib_request_kw): | |
""" | |
Perform a request on a given urllib connection object taken from our | |
pool. | |
:param conn: | |
a connection from one of our connection pools | |
:param timeout: | |
Socket timeout in seconds for the request. This can be a | |
float or integer, which will set the same timeout value for | |
the socket connect and the socket read, or an instance of | |
:class:`urllib3.util.Timeout`, which gives you more fine-grained | |
control over your timeouts. | |
""" | |
self.num_requests += 1 | |
timeout_obj = self._get_timeout(timeout) | |
timeout_obj.start_connect() | |
conn.timeout = timeout_obj.connect_timeout | |
# Trigger any extra validation we need to do. | |
try: | |
self._validate_conn(conn) | |
except (SocketTimeout, BaseSSLError) as e: | |
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout. | |
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) | |
raise | |
# conn.request() calls httplib.*.request, not the method in | |
# urllib3.request. It also calls makefile (recv) on the socket. | |
if chunked: | |
conn.request_chunked(method, url, **httplib_request_kw) | |
else: | |
> conn.request(method, url, **httplib_request_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:354: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
method = 'POST', url = '/seldon/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.9404752763052208, 0.961519255562848, 0.46092393059667414, 0.6530442627920168]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '172', 'Content-Type': 'application/json'} | |
def request(self, method, url, body=None, headers={}, *, | |
encode_chunked=False): | |
"""Send a complete request to the server.""" | |
> self._send_request(method, url, body, headers, encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1229: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
method = 'POST', url = '/seldon/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.9404752763052208, 0.961519255562848, 0.46092393059667414, 0.6530442627920168]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '172', 'Content-Type': 'application/json'} | |
encode_chunked = False | |
def _send_request(self, method, url, body, headers, encode_chunked): | |
# Honor explicitly requested Host: and Accept-Encoding: headers. | |
header_names = frozenset(k.lower() for k in headers) | |
skips = {} | |
if 'host' in header_names: | |
skips['skip_host'] = 1 | |
if 'accept-encoding' in header_names: | |
skips['skip_accept_encoding'] = 1 | |
self.putrequest(method, url, **skips) | |
# chunked encoding will happen if HTTP/1.1 is used and either | |
# the caller passes encode_chunked=True or the following | |
# conditions hold: | |
# 1. content-length has not been explicitly set | |
# 2. the body is a file or iterable, but not a str or bytes-like | |
# 3. Transfer-Encoding has NOT been explicitly set by the caller | |
if 'content-length' not in header_names: | |
# only chunk body if not explicitly set for backwards | |
# compatibility, assuming the client code is already handling the | |
# chunking | |
if 'transfer-encoding' not in header_names: | |
# if content-length cannot be automatically determined, fall | |
# back to chunked encoding | |
encode_chunked = False | |
content_length = self._get_content_length(body, method) | |
if content_length is None: | |
if body is not None: | |
if self.debuglevel > 0: | |
print('Unable to determine size of %r' % body) | |
encode_chunked = True | |
self.putheader('Transfer-Encoding', 'chunked') | |
else: | |
self.putheader('Content-Length', str(content_length)) | |
else: | |
encode_chunked = False | |
for hdr, value in headers.items(): | |
self.putheader(hdr, value) | |
if isinstance(body, str): | |
# RFC 2616 Section 3.7.1 says that text default has a | |
# default charset of iso-8859-1. | |
body = _encode(body, 'body') | |
> self.endheaders(body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1275: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.9404752763052208, 0.961519255562848, 0.46092393059667414, 0.6530442627920168]}}}' | |
def endheaders(self, message_body=None, *, encode_chunked=False): | |
"""Indicate that the last header line has been sent to the server. | |
This method sends the request to the server. The optional message_body | |
argument can be used to pass a message body associated with the | |
request. | |
""" | |
if self.__state == _CS_REQ_STARTED: | |
self.__state = _CS_REQ_SENT | |
else: | |
raise CannotSendHeader() | |
> self._send_output(message_body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1224: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.9404752763052208, 0.961519255562848, 0.46092393059667414, 0.6530442627920168]}}}' | |
encode_chunked = False | |
def _send_output(self, message_body=None, encode_chunked=False): | |
"""Send the currently buffered request and clear the buffer. | |
Appends an extra \\r\\n to the buffer. | |
A message_body may be specified, to be appended to the request. | |
""" | |
self._buffer.extend((b"", b"")) | |
msg = b"\r\n".join(self._buffer) | |
del self._buffer[:] | |
> self.send(msg) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1016: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
data = b'POST /seldon/myabtest/api/v0.1/predictions HTTP/1.1\r\nHost: localhost:8003\r\nUser-Agent: python-requests/2.21.0\r\...zip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 172\r\nContent-Type: application/json\r\n\r\n' | |
def send(self, data): | |
"""Send `data' to the server. | |
``data`` can be a string object, a bytes object, an array object, a | |
file-like object that supports a .read() method, or an iterable object. | |
""" | |
if self.sock is None: | |
if self.auto_open: | |
> self.connect() | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:956: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
def connect(self): | |
> conn = self._new_conn() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:181: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f05127550> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
(self._dns_host, self.port), self.timeout, **extra_kw) | |
except SocketTimeout as e: | |
raise ConnectTimeoutError( | |
self, "Connection to %s timed out. (connect timeout=%s)" % | |
(self.host, self.timeout)) | |
except SocketError as e: | |
raise NewConnectionError( | |
> self, "Failed to establish a new connection: %s" % e) | |
E urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5f05127550>: Failed to establish a new connection: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:168: NewConnectionError | |
During handling of the above exception, another exception occurred: | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f050d9940> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f05127860>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
> timeout=timeout | |
) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:449: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f05127b70> | |
method = 'POST', url = '/seldon/myabtest/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.4951476615415631, 0.9404752763052208, 0.961519255562848, 0.46092393059667414, 0.6530442627920168]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '172', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f05127860> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f051273c8> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
chunked=chunked) | |
# If we're going to release the connection in ``finally:``, then | |
# the response doesn't need to know about the connection. Otherwise | |
# it will also try to release it and we'll have a double-release | |
# mess. | |
response_conn = conn if not release_conn else None | |
# Pass method to Response for length checking | |
response_kw['request_method'] = method | |
# Import httplib's response into our own wrapper object | |
response = self.ResponseCls.from_httplib(httplib_response, | |
pool=self, | |
connection=response_conn, | |
retries=retries, | |
**response_kw) | |
# Everything went great! | |
clean_exit = True | |
except queue.Empty: | |
# Timed out by queue. | |
raise EmptyPoolError(self, "No pool connections are available.") | |
except (TimeoutError, HTTPException, SocketError, ProtocolError, | |
BaseSSLError, SSLError, CertificateError) as e: | |
# Discard the connection for these exceptions. It will be | |
# replaced during the next _get_conn() call. | |
clean_exit = False | |
if isinstance(e, (BaseSSLError, CertificateError)): | |
e = SSLError(e) | |
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy: | |
e = ProxyError('Cannot connect to proxy.', e) | |
elif isinstance(e, (SocketError, HTTPException)): | |
e = ProtocolError('Connection aborted.', e) | |
retries = retries.increment(method, url, error=e, _pool=self, | |
> _stacktrace=sys.exc_info()[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:638: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
method = 'POST', url = '/seldon/myabtest/api/v0.1/predictions', response = None | |
error = NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f05127550>: Failed to establish a new connection: [Errno 111] Connection refused') | |
_pool = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f05127b70> | |
_stacktrace = <traceback object at 0x7f5f0512a648> | |
def increment(self, method=None, url=None, response=None, error=None, | |
_pool=None, _stacktrace=None): | |
""" Return a new Retry object with incremented retry counters. | |
:param response: A response object, or None, if the server did not | |
return a response. | |
:type response: :class:`~urllib3.response.HTTPResponse` | |
:param Exception error: An error encountered during the request, or | |
None if the response was received successfully. | |
:return: A new ``Retry`` object. | |
""" | |
if self.total is False and error: | |
# Disabled, indicate to re-raise the error. | |
raise six.reraise(type(error), error, _stacktrace) | |
total = self.total | |
if total is not None: | |
total -= 1 | |
connect = self.connect | |
read = self.read | |
redirect = self.redirect | |
status_count = self.status | |
cause = 'unknown' | |
status = None | |
redirect_location = None | |
if error and self._is_connection_error(error): | |
# Connect retry? | |
if connect is False: | |
raise six.reraise(type(error), error, _stacktrace) | |
elif connect is not None: | |
connect -= 1 | |
elif error and self._is_read_error(error): | |
# Read retry? | |
if read is False or not self._is_method_retryable(method): | |
raise six.reraise(type(error), error, _stacktrace) | |
elif read is not None: | |
read -= 1 | |
elif response and response.get_redirect_location(): | |
# Redirect retry? | |
if redirect is not None: | |
redirect -= 1 | |
cause = 'too many redirects' | |
redirect_location = response.get_redirect_location() | |
status = response.status | |
else: | |
# Incrementing because of a server error like a 500 in | |
# status_forcelist and a the given method is in the whitelist | |
cause = ResponseError.GENERIC_ERROR | |
if response and response.status: | |
if status_count is not None: | |
status_count -= 1 | |
cause = ResponseError.SPECIFIC_ERROR.format( | |
status_code=response.status) | |
status = response.status | |
history = self.history + (RequestHistory(method, url, error, status, redirect_location),) | |
new_retry = self.new( | |
total=total, | |
connect=connect, read=read, redirect=redirect, status=status_count, | |
history=history) | |
if new_retry.is_exhausted(): | |
> raise MaxRetryError(_pool, url, error or ResponseError(cause)) | |
E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/myabtest/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f05127550>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py:398: MaxRetryError | |
During handling of the above exception, another exception occurred: | |
self = <test_ksonnet_single_namespace.TestSingleNamespace object at 0x7f5f05127748> | |
def test_abtest_model(self): | |
run('cd my-model && ks delete default && ks component rm mymodel', shell=True) | |
run('kubectl delete sdep --all', shell=True) | |
run('cd my-model && ks generate seldon-abtest-v1alpha2 myabtest --imageA seldonio/mock_classifier:1.0 --imageB seldonio/mock_classifier:1.0 --oauthKey=oauth-key --oauthSecret=oauth-secret && ks apply default -c myabtest', shell=True) | |
wait_for_rollout("myabtest-myabtest-41de5b8") | |
wait_for_rollout("myabtest-myabtest-df66c5c") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret",None,API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
> r = rest_request_ambassador("myabtest",None,API_AMBASSADOR) | |
test_ksonnet_single_namespace.py:70: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:76: in rest_request_ambassador | |
json=payload) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:116: in post | |
return request('post', url, data=data, json=json, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:60: in request | |
return session.request(method=method, url=url, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:533: in request | |
resp = self.send(prep, **send_kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:646: in send | |
r = adapter.send(request, **kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f050d9940> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f05127860>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
timeout=timeout | |
) | |
# Send the request. | |
else: | |
if hasattr(conn, 'proxy_pool'): | |
conn = conn.proxy_pool | |
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) | |
try: | |
low_conn.putrequest(request.method, | |
url, | |
skip_accept_encoding=True) | |
for header, value in request.headers.items(): | |
low_conn.putheader(header, value) | |
low_conn.endheaders() | |
for i in request.body: | |
low_conn.send(hex(len(i))[2:].encode('utf-8')) | |
low_conn.send(b'\r\n') | |
low_conn.send(i) | |
low_conn.send(b'\r\n') | |
low_conn.send(b'0\r\n\r\n') | |
# Receive the response from the server | |
try: | |
# For Python 2.7, use buffering of HTTP responses | |
r = low_conn.getresponse(buffering=True) | |
except TypeError: | |
# For compatibility with Python 3.3+ | |
r = low_conn.getresponse() | |
resp = HTTPResponse.from_httplib( | |
r, | |
pool=conn, | |
connection=low_conn, | |
preload_content=False, | |
decode_content=False | |
) | |
except: | |
# If we hit any problems here, clean up the connection. | |
# Then, reraise so that we can handle the actual exception. | |
low_conn.close() | |
raise | |
except (ProtocolError, socket.error) as err: | |
raise ConnectionError(err, request=request) | |
except MaxRetryError as e: | |
if isinstance(e.reason, ConnectTimeoutError): | |
# TODO: Remove this in 3.0.0: see #2811 | |
if not isinstance(e.reason, NewConnectionError): | |
raise ConnectTimeout(e, request=request) | |
if isinstance(e.reason, ResponseError): | |
raise RetryError(e, request=request) | |
if isinstance(e.reason, _ProxyError): | |
raise ProxyError(e, request=request) | |
if isinstance(e.reason, _SSLError): | |
# This branch is for urllib3 v1.22 and later. | |
raise SSLError(e, request=request) | |
> raise ConnectionError(e, request=request) | |
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/myabtest/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f05127550>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError | |
______________________ TestSingleNamespace.test_mab_model ______________________ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
> (self._dns_host, self.port), self.timeout, **extra_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:159: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
sock.connect(sa) | |
return sock | |
except socket.error as e: | |
err = e | |
if sock is not None: | |
sock.close() | |
sock = None | |
if err is not None: | |
> raise err | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:80: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
address = ('localhost', 8003), timeout = None, source_address = None | |
socket_options = [(6, 1, 1)] | |
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
source_address=None, socket_options=None): | |
"""Connect to *address* and return the socket object. | |
Convenience function. Connect to *address* (a 2-tuple ``(host, | |
port)``) and return the socket object. Passing the optional | |
*timeout* parameter will set the timeout on the socket instance | |
before attempting to connect. If no *timeout* is supplied, the | |
global default timeout setting returned by :func:`getdefaulttimeout` | |
is used. If *source_address* is set it must be a tuple of (host, port) | |
for the socket to bind as a source address before making the connection. | |
An host of '' or port 0 tells the OS to use the default. | |
""" | |
host, port = address | |
if host.startswith('['): | |
host = host.strip('[]') | |
err = None | |
# Using the value from allowed_gai_family() in the context of getaddrinfo lets | |
# us select whether to work with IPv4 DNS records, IPv6 records, or both. | |
# The original create_connection function always returns all records. | |
family = allowed_gai_family() | |
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): | |
af, socktype, proto, canonname, sa = res | |
sock = None | |
try: | |
sock = socket.socket(af, socktype, proto) | |
# If provided, set socket level options before connecting. | |
_set_socket_options(sock, socket_options) | |
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT: | |
sock.settimeout(timeout) | |
if source_address: | |
sock.bind(source_address) | |
> sock.connect(sa) | |
E ConnectionRefusedError: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py:70: ConnectionRefusedError | |
During handling of the above exception, another exception occurred: | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0520dc88> | |
method = 'POST', url = '/seldon/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.6316606860112896, 0.34654430612586096, 0.5686328972993486, 0.9330674237228661]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0520d438> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0520d278> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
> chunked=chunked) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:600: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0520dc88> | |
conn = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
method = 'POST', url = '/seldon/mymab/api/v0.1/predictions' | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0520d278> | |
chunked = False | |
httplib_request_kw = {'body': b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.631660686011289...p, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'}} | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0520dd30> | |
def _make_request(self, conn, method, url, timeout=_Default, chunked=False, | |
**httplib_request_kw): | |
""" | |
Perform a request on a given urllib connection object taken from our | |
pool. | |
:param conn: | |
a connection from one of our connection pools | |
:param timeout: | |
Socket timeout in seconds for the request. This can be a | |
float or integer, which will set the same timeout value for | |
the socket connect and the socket read, or an instance of | |
:class:`urllib3.util.Timeout`, which gives you more fine-grained | |
control over your timeouts. | |
""" | |
self.num_requests += 1 | |
timeout_obj = self._get_timeout(timeout) | |
timeout_obj.start_connect() | |
conn.timeout = timeout_obj.connect_timeout | |
# Trigger any extra validation we need to do. | |
try: | |
self._validate_conn(conn) | |
except (SocketTimeout, BaseSSLError) as e: | |
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout. | |
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout) | |
raise | |
# conn.request() calls httplib.*.request, not the method in | |
# urllib3.request. It also calls makefile (recv) on the socket. | |
if chunked: | |
conn.request_chunked(method, url, **httplib_request_kw) | |
else: | |
> conn.request(method, url, **httplib_request_kw) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:354: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
method = 'POST', url = '/seldon/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.6316606860112896, 0.34654430612586096, 0.5686328972993486, 0.9330674237228661]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
def request(self, method, url, body=None, headers={}, *, | |
encode_chunked=False): | |
"""Send a complete request to the server.""" | |
> self._send_request(method, url, body, headers, encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1229: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
method = 'POST', url = '/seldon/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.6316606860112896, 0.34654430612586096, 0.5686328972993486, 0.9330674237228661]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
encode_chunked = False | |
def _send_request(self, method, url, body, headers, encode_chunked): | |
# Honor explicitly requested Host: and Accept-Encoding: headers. | |
header_names = frozenset(k.lower() for k in headers) | |
skips = {} | |
if 'host' in header_names: | |
skips['skip_host'] = 1 | |
if 'accept-encoding' in header_names: | |
skips['skip_accept_encoding'] = 1 | |
self.putrequest(method, url, **skips) | |
# chunked encoding will happen if HTTP/1.1 is used and either | |
# the caller passes encode_chunked=True or the following | |
# conditions hold: | |
# 1. content-length has not been explicitly set | |
# 2. the body is a file or iterable, but not a str or bytes-like | |
# 3. Transfer-Encoding has NOT been explicitly set by the caller | |
if 'content-length' not in header_names: | |
# only chunk body if not explicitly set for backwards | |
# compatibility, assuming the client code is already handling the | |
# chunking | |
if 'transfer-encoding' not in header_names: | |
# if content-length cannot be automatically determined, fall | |
# back to chunked encoding | |
encode_chunked = False | |
content_length = self._get_content_length(body, method) | |
if content_length is None: | |
if body is not None: | |
if self.debuglevel > 0: | |
print('Unable to determine size of %r' % body) | |
encode_chunked = True | |
self.putheader('Transfer-Encoding', 'chunked') | |
else: | |
self.putheader('Content-Length', str(content_length)) | |
else: | |
encode_chunked = False | |
for hdr, value in headers.items(): | |
self.putheader(hdr, value) | |
if isinstance(body, str): | |
# RFC 2616 Section 3.7.1 says that text default has a | |
# default charset of iso-8859-1. | |
body = _encode(body, 'body') | |
> self.endheaders(body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1275: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.6316606860112896, 0.34654430612586096, 0.5686328972993486, 0.9330674237228661]}}}' | |
def endheaders(self, message_body=None, *, encode_chunked=False): | |
"""Indicate that the last header line has been sent to the server. | |
This method sends the request to the server. The optional message_body | |
argument can be used to pass a message body associated with the | |
request. | |
""" | |
if self.__state == _CS_REQ_STARTED: | |
self.__state = _CS_REQ_SENT | |
else: | |
raise CannotSendHeader() | |
> self._send_output(message_body, encode_chunked=encode_chunked) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1224: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
message_body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.6316606860112896, 0.34654430612586096, 0.5686328972993486, 0.9330674237228661]}}}' | |
encode_chunked = False | |
def _send_output(self, message_body=None, encode_chunked=False): | |
"""Send the currently buffered request and clear the buffer. | |
Appends an extra \\r\\n to the buffer. | |
A message_body may be specified, to be appended to the request. | |
""" | |
self._buffer.extend((b"", b"")) | |
msg = b"\r\n".join(self._buffer) | |
del self._buffer[:] | |
> self.send(msg) | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:1016: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
data = b'POST /seldon/mymab/api/v0.1/predictions HTTP/1.1\r\nHost: localhost:8003\r\nUser-Agent: python-requests/2.21.0\r\nAc...zip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 173\r\nContent-Type: application/json\r\n\r\n' | |
def send(self, data): | |
"""Send `data' to the server. | |
``data`` can be a string object, a bytes object, an array object, a | |
file-like object that supports a .read() method, or an iterable object. | |
""" | |
if self.sock is None: | |
if self.auto_open: | |
> self.connect() | |
/home/ryan/anaconda3/lib/python3.7/http/client.py:956: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
def connect(self): | |
> conn = self._new_conn() | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:181: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connection.HTTPConnection object at 0x7f5f0520da58> | |
def _new_conn(self): | |
""" Establish a socket connection and set nodelay settings on it. | |
:return: New socket connection. | |
""" | |
extra_kw = {} | |
if self.source_address: | |
extra_kw['source_address'] = self.source_address | |
if self.socket_options: | |
extra_kw['socket_options'] = self.socket_options | |
try: | |
conn = connection.create_connection( | |
(self._dns_host, self.port), self.timeout, **extra_kw) | |
except SocketTimeout as e: | |
raise ConnectTimeoutError( | |
self, "Connection to %s timed out. (connect timeout=%s)" % | |
(self.host, self.timeout)) | |
except SocketError as e: | |
raise NewConnectionError( | |
> self, "Failed to establish a new connection: %s" % e) | |
E urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5f0520da58>: Failed to establish a new connection: [Errno 111] Connection refused | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connection.py:168: NewConnectionError | |
During handling of the above exception, another exception occurred: | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f0520d860> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0520d438>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
> timeout=timeout | |
) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:449: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0520dc88> | |
method = 'POST', url = '/seldon/mymab/api/v0.1/predictions' | |
body = b'{"data": {"names": ["a", "b"], "tensor": {"shape": [1, 5], "values": [0.7602070327185024, 0.6316606860112896, 0.34654430612586096, 0.5686328972993486, 0.9330674237228661]}}}' | |
headers = {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '173', 'Content-Type': 'application/json'} | |
retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
redirect = False, assert_same_host = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0520d438> | |
pool_timeout = None, release_conn = False, chunked = False, body_pos = None | |
response_kw = {'decode_content': False, 'preload_content': False}, conn = None | |
release_this_conn = True, err = None, clean_exit = False | |
timeout_obj = <urllib3.util.timeout.Timeout object at 0x7f5f0520d278> | |
is_new_proxy_conn = False | |
def urlopen(self, method, url, body=None, headers=None, retries=None, | |
redirect=True, assert_same_host=True, timeout=_Default, | |
pool_timeout=None, release_conn=None, chunked=False, | |
body_pos=None, **response_kw): | |
""" | |
Get a connection from the pool and perform an HTTP request. This is the | |
lowest level call for making a request, so you'll need to specify all | |
the raw details. | |
.. note:: | |
More commonly, it's appropriate to use a convenience method provided | |
by :class:`.RequestMethods`, such as :meth:`request`. | |
.. note:: | |
`release_conn` will only behave as expected if | |
`preload_content=False` because we want to make | |
`preload_content=False` the default behaviour someday soon without | |
breaking backwards compatibility. | |
:param method: | |
HTTP request method (such as GET, POST, PUT, etc.) | |
:param body: | |
Data to send in the request body (useful for creating | |
POST requests, see HTTPConnectionPool.post_url for | |
more convenience). | |
:param headers: | |
Dictionary of custom headers to send, such as User-Agent, | |
If-None-Match, etc. If None, pool headers are used. If provided, | |
these headers completely replace any pool-specific headers. | |
:param retries: | |
Configure the number of retries to allow before raising a | |
:class:`~urllib3.exceptions.MaxRetryError` exception. | |
Pass ``None`` to retry until you receive a response. Pass a | |
:class:`~urllib3.util.retry.Retry` object for fine-grained control | |
over different types of retries. | |
Pass an integer number to retry connection errors that many times, | |
but no other types of errors. Pass zero to never retry. | |
If ``False``, then retries are disabled and any exception is raised | |
immediately. Also, instead of raising a MaxRetryError on redirects, | |
the redirect response will be returned. | |
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. | |
:param redirect: | |
If True, automatically handle redirects (status codes 301, 302, | |
303, 307, 308). Each redirect counts as a retry. Disabling retries | |
will disable redirect, too. | |
:param assert_same_host: | |
If ``True``, will make sure that the host of the pool requests is | |
consistent else will raise HostChangedError. When False, you can | |
use the pool on an HTTP proxy and request foreign hosts. | |
:param timeout: | |
If specified, overrides the default timeout for this one | |
request. It may be a float (in seconds) or an instance of | |
:class:`urllib3.util.Timeout`. | |
:param pool_timeout: | |
If set and the pool is set to block=True, then this method will | |
block for ``pool_timeout`` seconds and raise EmptyPoolError if no | |
connection is available within the time period. | |
:param release_conn: | |
If False, then the urlopen call will not release the connection | |
back into the pool once a response is received (but will release if | |
you read the entire contents of the response such as when | |
`preload_content=True`). This is useful if you're not preloading | |
the response's content immediately. You will need to call | |
``r.release_conn()`` on the response ``r`` to return the connection | |
back into the pool. If None, it takes the value of | |
``response_kw.get('preload_content', True)``. | |
:param chunked: | |
If True, urllib3 will send the body using chunked transfer | |
encoding. Otherwise, urllib3 will send the body using the standard | |
content-length form. Defaults to False. | |
:param int body_pos: | |
Position to seek to in file-like body in the event of a retry or | |
redirect. Typically this won't need to be set because urllib3 will | |
auto-populate the value when needed. | |
:param \\**response_kw: | |
Additional parameters are passed to | |
:meth:`urllib3.response.HTTPResponse.from_httplib` | |
""" | |
if headers is None: | |
headers = self.headers | |
if not isinstance(retries, Retry): | |
retries = Retry.from_int(retries, redirect=redirect, default=self.retries) | |
if release_conn is None: | |
release_conn = response_kw.get('preload_content', True) | |
# Check host | |
if assert_same_host and not self.is_same_host(url): | |
raise HostChangedError(self, url, retries) | |
conn = None | |
# Track whether `conn` needs to be released before | |
# returning/raising/recursing. Update this variable if necessary, and | |
# leave `release_conn` constant throughout the function. That way, if | |
# the function recurses, the original value of `release_conn` will be | |
# passed down into the recursive call, and its value will be respected. | |
# | |
# See issue #651 [1] for details. | |
# | |
# [1] <https://github.com/shazow/urllib3/issues/651> | |
release_this_conn = release_conn | |
# Merge the proxy headers. Only do this in HTTP. We have to copy the | |
# headers dict so we can safely change it without those changes being | |
# reflected in anyone else's copy. | |
if self.scheme == 'http': | |
headers = headers.copy() | |
headers.update(self.proxy_headers) | |
# Must keep the exception bound to a separate variable or else Python 3 | |
# complains about UnboundLocalError. | |
err = None | |
# Keep track of whether we cleanly exited the except block. This | |
# ensures we do proper cleanup in finally. | |
clean_exit = False | |
# Rewind body position, if needed. Record current position | |
# for future rewinds in the event of a redirect/retry. | |
body_pos = set_file_position(body, body_pos) | |
try: | |
# Request a connection from the queue. | |
timeout_obj = self._get_timeout(timeout) | |
conn = self._get_conn(timeout=pool_timeout) | |
conn.timeout = timeout_obj.connect_timeout | |
is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None) | |
if is_new_proxy_conn: | |
self._prepare_proxy(conn) | |
# Make the request on the httplib connection object. | |
httplib_response = self._make_request(conn, method, url, | |
timeout=timeout_obj, | |
body=body, headers=headers, | |
chunked=chunked) | |
# If we're going to release the connection in ``finally:``, then | |
# the response doesn't need to know about the connection. Otherwise | |
# it will also try to release it and we'll have a double-release | |
# mess. | |
response_conn = conn if not release_conn else None | |
# Pass method to Response for length checking | |
response_kw['request_method'] = method | |
# Import httplib's response into our own wrapper object | |
response = self.ResponseCls.from_httplib(httplib_response, | |
pool=self, | |
connection=response_conn, | |
retries=retries, | |
**response_kw) | |
# Everything went great! | |
clean_exit = True | |
except queue.Empty: | |
# Timed out by queue. | |
raise EmptyPoolError(self, "No pool connections are available.") | |
except (TimeoutError, HTTPException, SocketError, ProtocolError, | |
BaseSSLError, SSLError, CertificateError) as e: | |
# Discard the connection for these exceptions. It will be | |
# replaced during the next _get_conn() call. | |
clean_exit = False | |
if isinstance(e, (BaseSSLError, CertificateError)): | |
e = SSLError(e) | |
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy: | |
e = ProxyError('Cannot connect to proxy.', e) | |
elif isinstance(e, (SocketError, HTTPException)): | |
e = ProtocolError('Connection aborted.', e) | |
retries = retries.increment(method, url, error=e, _pool=self, | |
> _stacktrace=sys.exc_info()[2]) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py:638: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = Retry(total=0, connect=None, read=False, redirect=None, status=None) | |
method = 'POST', url = '/seldon/mymab/api/v0.1/predictions', response = None | |
error = NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0520da58>: Failed to establish a new connection: [Errno 111] Connection refused') | |
_pool = <urllib3.connectionpool.HTTPConnectionPool object at 0x7f5f0520dc88> | |
_stacktrace = <traceback object at 0x7f5f051b85c8> | |
def increment(self, method=None, url=None, response=None, error=None, | |
_pool=None, _stacktrace=None): | |
""" Return a new Retry object with incremented retry counters. | |
:param response: A response object, or None, if the server did not | |
return a response. | |
:type response: :class:`~urllib3.response.HTTPResponse` | |
:param Exception error: An error encountered during the request, or | |
None if the response was received successfully. | |
:return: A new ``Retry`` object. | |
""" | |
if self.total is False and error: | |
# Disabled, indicate to re-raise the error. | |
raise six.reraise(type(error), error, _stacktrace) | |
total = self.total | |
if total is not None: | |
total -= 1 | |
connect = self.connect | |
read = self.read | |
redirect = self.redirect | |
status_count = self.status | |
cause = 'unknown' | |
status = None | |
redirect_location = None | |
if error and self._is_connection_error(error): | |
# Connect retry? | |
if connect is False: | |
raise six.reraise(type(error), error, _stacktrace) | |
elif connect is not None: | |
connect -= 1 | |
elif error and self._is_read_error(error): | |
# Read retry? | |
if read is False or not self._is_method_retryable(method): | |
raise six.reraise(type(error), error, _stacktrace) | |
elif read is not None: | |
read -= 1 | |
elif response and response.get_redirect_location(): | |
# Redirect retry? | |
if redirect is not None: | |
redirect -= 1 | |
cause = 'too many redirects' | |
redirect_location = response.get_redirect_location() | |
status = response.status | |
else: | |
# Incrementing because of a server error like a 500 in | |
# status_forcelist and a the given method is in the whitelist | |
cause = ResponseError.GENERIC_ERROR | |
if response and response.status: | |
if status_count is not None: | |
status_count -= 1 | |
cause = ResponseError.SPECIFIC_ERROR.format( | |
status_code=response.status) | |
status = response.status | |
history = self.history + (RequestHistory(method, url, error, status, redirect_location),) | |
new_retry = self.new( | |
total=total, | |
connect=connect, read=read, redirect=redirect, status=status_count, | |
history=history) | |
if new_retry.is_exhausted(): | |
> raise MaxRetryError(_pool, url, error or ResponseError(cause)) | |
E urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/mymab/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0520da58>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py:398: MaxRetryError | |
During handling of the above exception, another exception occurred: | |
self = <test_ksonnet_single_namespace.TestSingleNamespace object at 0x7f5f04eea5f8> | |
def test_mab_model(self): | |
run('cd my-model && ks delete default && ks component rm mymab', shell=True) | |
run('kubectl delete sdep --all', shell=True) | |
run('cd my-model && ks generate seldon-mab-v1alpha2 mymab --imageA seldonio/mock_classifier:1.0 --imageB seldonio/mock_classifier:1.0 --oauthKey=oauth-key --oauthSecret=oauth-secret && ks apply default -c mymab', shell=True) | |
wait_for_rollout("mymab-mymab-41de5b8") | |
wait_for_rollout("mymab-mymab-b8038b2") | |
wait_for_rollout("mymab-mymab-df66c5c") | |
r = initial_rest_request() | |
r = rest_request_api_gateway("oauth-key","oauth-secret",None,API_GATEWAY_REST) | |
res = r.json() | |
print(res) | |
assert r.status_code == 200 | |
assert len(r.json()["data"]["tensor"]["values"]) == 1 | |
> r = rest_request_ambassador("mymab",None,API_AMBASSADOR) | |
test_ksonnet_single_namespace.py:95: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
seldon_utils.py:76: in rest_request_ambassador | |
json=payload) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:116: in post | |
return request('post', url, data=data, json=json, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/api.py:60: in request | |
return session.request(method=method, url=url, **kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:533: in request | |
resp = self.send(prep, **send_kwargs) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/sessions.py:646: in send | |
r = adapter.send(request, **kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <requests.adapters.HTTPAdapter object at 0x7f5f0520d860> | |
request = <PreparedRequest [POST]>, stream = False | |
timeout = <urllib3.util.timeout.Timeout object at 0x7f5f0520d438>, verify = True | |
cert = None, proxies = OrderedDict() | |
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): | |
"""Sends PreparedRequest object. Returns Response object. | |
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent. | |
:param stream: (optional) Whether to stream the request content. | |
:param timeout: (optional) How long to wait for the server to send | |
data before giving up, as a float, or a :ref:`(connect timeout, | |
read timeout) <timeouts>` tuple. | |
:type timeout: float or tuple or urllib3 Timeout object | |
:param verify: (optional) Either a boolean, in which case it controls whether | |
we verify the server's TLS certificate, or a string, in which case it | |
must be a path to a CA bundle to use | |
:param cert: (optional) Any user-provided SSL certificate to be trusted. | |
:param proxies: (optional) The proxies dictionary to apply to the request. | |
:rtype: requests.Response | |
""" | |
try: | |
conn = self.get_connection(request.url, proxies) | |
except LocationValueError as e: | |
raise InvalidURL(e, request=request) | |
self.cert_verify(conn, request.url, verify, cert) | |
url = self.request_url(request, proxies) | |
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) | |
chunked = not (request.body is None or 'Content-Length' in request.headers) | |
if isinstance(timeout, tuple): | |
try: | |
connect, read = timeout | |
timeout = TimeoutSauce(connect=connect, read=read) | |
except ValueError as e: | |
# this may raise a string formatting error. | |
err = ("Invalid timeout {}. Pass a (connect, read) " | |
"timeout tuple, or a single float to set " | |
"both timeouts to the same value".format(timeout)) | |
raise ValueError(err) | |
elif isinstance(timeout, TimeoutSauce): | |
pass | |
else: | |
timeout = TimeoutSauce(connect=timeout, read=timeout) | |
try: | |
if not chunked: | |
resp = conn.urlopen( | |
method=request.method, | |
url=url, | |
body=request.body, | |
headers=request.headers, | |
redirect=False, | |
assert_same_host=False, | |
preload_content=False, | |
decode_content=False, | |
retries=self.max_retries, | |
timeout=timeout | |
) | |
# Send the request. | |
else: | |
if hasattr(conn, 'proxy_pool'): | |
conn = conn.proxy_pool | |
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) | |
try: | |
low_conn.putrequest(request.method, | |
url, | |
skip_accept_encoding=True) | |
for header, value in request.headers.items(): | |
low_conn.putheader(header, value) | |
low_conn.endheaders() | |
for i in request.body: | |
low_conn.send(hex(len(i))[2:].encode('utf-8')) | |
low_conn.send(b'\r\n') | |
low_conn.send(i) | |
low_conn.send(b'\r\n') | |
low_conn.send(b'0\r\n\r\n') | |
# Receive the response from the server | |
try: | |
# For Python 2.7, use buffering of HTTP responses | |
r = low_conn.getresponse(buffering=True) | |
except TypeError: | |
# For compatibility with Python 3.3+ | |
r = low_conn.getresponse() | |
resp = HTTPResponse.from_httplib( | |
r, | |
pool=conn, | |
connection=low_conn, | |
preload_content=False, | |
decode_content=False | |
) | |
except: | |
# If we hit any problems here, clean up the connection. | |
# Then, reraise so that we can handle the actual exception. | |
low_conn.close() | |
raise | |
except (ProtocolError, socket.error) as err: | |
raise ConnectionError(err, request=request) | |
except MaxRetryError as e: | |
if isinstance(e.reason, ConnectTimeoutError): | |
# TODO: Remove this in 3.0.0: see #2811 | |
if not isinstance(e.reason, NewConnectionError): | |
raise ConnectTimeout(e, request=request) | |
if isinstance(e.reason, ResponseError): | |
raise RetryError(e, request=request) | |
if isinstance(e.reason, _ProxyError): | |
raise ProxyError(e, request=request) | |
if isinstance(e.reason, _SSLError): | |
# This branch is for urllib3 v1.22 and later. | |
raise SSLError(e, request=request) | |
> raise ConnectionError(e, request=request) | |
E requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8003): Max retries exceeded with url: /seldon/mymab/api/v0.1/predictions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f0520da58>: Failed to establish a new connection: [Errno 111] Connection refused')) | |
/home/ryan/anaconda3/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError | |
==================== 7 failed, 35 passed in 2529.43 seconds ==================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment