本文整理汇总了Python中tornado.log.app_log.warning函数的典型用法代码示例。如果您正苦于以下问题:Python warning函数的具体用法?Python warning怎么用?Python warning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warning函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_for_http_server
def wait_for_http_server(url, timeout=10):
"""Wait for an HTTP Server to respond at url.
Any non-5XX response code will do, even 404.
"""
loop = ioloop.IOLoop.current()
tic = loop.time()
client = AsyncHTTPClient()
while loop.time() - tic < timeout:
try:
r = yield client.fetch(url, follow_redirects=False)
except HTTPError as e:
if e.code >= 500:
# failed to respond properly, wait and try again
if e.code != 599:
# we expect 599 for no connection,
# but 502 or other proxy error is conceivable
app_log.warning(
"Server at %s responded with error: %s", url, e.code)
yield gen.sleep(0.1)
else:
app_log.debug("Server at %s responded with %s", url, e.code)
return
except (OSError, socket.error) as e:
if e.errno not in {errno.ECONNABORTED, errno.ECONNREFUSED, errno.ECONNRESET}:
app_log.warning("Failed to connect to %s (%s)", url, e)
yield gen.sleep(0.1)
else:
return
raise TimeoutError(
"Server at {url} didn't respond in {timeout} seconds".format(**locals())
)
示例2: _api_request
def _api_request(self, method, url, **kwargs):
"""Make an API request"""
allow_404 = kwargs.pop('allow_404', False)
headers = kwargs.setdefault('headers', {})
headers.setdefault('Authorization', 'token %s' % self.api_token)
try:
r = requests.request(method, url, **kwargs)
except requests.ConnectionError as e:
app_log.error("Error connecting to %s: %s", self.api_url, e)
msg = "Failed to connect to Hub API at %r." % self.api_url
msg += " Is the Hub accessible at this URL (from host: %s)?" % socket.gethostname()
if '127.0.0.1' in self.api_url:
msg += " Make sure to set c.JupyterHub.hub_ip to an IP accessible to" + \
" single-user servers if the servers are not on the same host as the Hub."
raise HTTPError(500, msg)
data = None
if r.status_code == 404 and allow_404:
pass
elif r.status_code == 403:
app_log.error("I don't have permission to check authorization with JupyterHub, my auth token may have expired: [%i] %s", r.status_code, r.reason)
app_log.error(r.text)
raise HTTPError(500, "Permission failure checking authorization, I may need a new token")
elif r.status_code >= 500:
app_log.error("Upstream failure verifying auth token: [%i] %s", r.status_code, r.reason)
app_log.error(r.text)
raise HTTPError(502, "Failed to check authorization (upstream problem)")
elif r.status_code >= 400:
app_log.warning("Failed to check authorization: [%i] %s", r.status_code, r.reason)
app_log.warning(r.text)
raise HTTPError(500, "Failed to check authorization")
else:
data = r.json()
return data
示例3: get
def get(self, path=None):
'''Spawns a brand new server'''
try:
if path is None:
# No path. Assign a prelaunched container from the pool and redirect to it.
# Append self.redirect_uri to the redirect target.
container_path = self.pool.acquire().path
app_log.info("Allocated [%s] from the pool.", container_path)
url = "/{}/{}".format(container_path, self.redirect_uri)
else:
path_parts = path.lstrip('/').split('/', 1)
container_path = path_parts[0]
# Scrap a container from the pool and replace it with an ad-hoc replacement.
# This takes longer, but is necessary to support ad-hoc containers
yield self.pool.adhoc(container_path)
app_log.info("Allocated ad-hoc container at [%s].", container_path)
url = path
app_log.debug("Redirecting [%s] -> [%s].", self.request.path, url)
self.redirect(url, permanent=False)
except spawnpool.EmptyPoolError:
app_log.warning("The container pool is empty!")
self.render("full.html", cull_period=self.cull_period)
示例4: _check_hub_authorization
def _check_hub_authorization(self, url, cache_key=None, use_cache=True):
"""Identify a user with the Hub
Args:
url (str): The API URL to check the Hub for authorization
(e.g. http://127.0.0.1:8081/hub/api/authorizations/token/abc-def)
cache_key (str): The key for checking the cache
use_cache (bool): Specify use_cache=False to skip cached cookie values (default: True)
Returns:
user_model (dict): The user model, if a user is identified, None if authentication fails.
Raises an HTTPError if the request failed for a reason other than no such user.
"""
if use_cache:
if cache_key is None:
raise ValueError("cache_key is required when using cache")
# check for a cached reply, so we don't check with the Hub if we don't have to
try:
return self.cache[cache_key]
except KeyError:
app_log.debug("HubAuth cache miss: %s", cache_key)
data = self._api_request('GET', url, allow_404=True)
if data is None:
app_log.warning("No Hub user identified for request")
else:
app_log.debug("Received request from Hub user %s", data)
if use_cache:
# cache result
self.cache[cache_key] = data
return data
示例5: get
def get(self):
error = self.get_argument("error", False)
if error:
msg = self.get_argument("error_description", error)
raise HTTPError(400, "Error in oauth: %s" % msg)
code = self.get_argument("code", False)
if not code:
raise HTTPError(400, "oauth callback made without a token")
# validate OAuth state
arg_state = self.get_argument("state", None)
if arg_state is None:
raise HTTPError("oauth state is missing. Try logging in again.")
cookie_name = self.hub_auth.get_state_cookie_name(arg_state)
cookie_state = self.get_secure_cookie(cookie_name)
# clear cookie state now that we've consumed it
self.clear_cookie(cookie_name, path=self.hub_auth.base_url)
if isinstance(cookie_state, bytes):
cookie_state = cookie_state.decode('ascii', 'replace')
# check that state matches
if arg_state != cookie_state:
app_log.warning("oauth state %r != %r", arg_state, cookie_state)
raise HTTPError(403, "oauth state does not match. Try logging in again.")
next_url = self.hub_auth.get_next_url(cookie_state)
# TODO: make async (in a Thread?)
token = self.hub_auth.token_for_code(code)
session_id = self.hub_auth.get_session_id(self)
user_model = self.hub_auth.user_for_token(token, session_id=session_id)
if user_model is None:
raise HTTPError(500, "oauth callback failed to identify a user")
app_log.info("Logged-in user %s", user_model)
self.hub_auth.set_cookie(self, token)
self.redirect(next_url or self.hub_auth.base_url)
示例6: get
def get(self, path=None):
'''Spawns a brand new server'''
if self.allow_origin:
self.set_header("Access-Control-Allow-Origin", self.allow_origin)
try:
if path is None:
# No path. Assign a prelaunched container from the pool and redirect to it.
# Append self.redirect_uri to the redirect target.
container_path = self.pool.acquire().path
app_log.info("Allocated [%s] from the pool.", container_path)
url = "/{}/{}".format(container_path, self.redirect_uri)
else:
# Split /user/{some_user}/long/url/path and acquire {some_user}
path_parts = path.lstrip('/').split('/', 2)
app_log.info("path parts: %s", path_parts)
user = path_parts[1]
# Scrap a container from the pool and replace it with an ad-hoc replacement.
# This takes longer, but is necessary to support ad-hoc containers
yield self.pool.adhoc(user, path_parts[-1])
url = "/" + "/".join(path_parts[:2])
app_log.info("new url: %s", url)
app_log.debug("Redirecting [%s] -> [%s].", self.request.path, url)
self.redirect(url, permanent=False)
except spawnpool.EmptyPoolError:
app_log.warning("The container pool is empty!")
self.render("full.html", cull_period=self.cull_period)
示例7: add_error_message_to_slug
def add_error_message_to_slug(self, error_string, args_to_delete=[], msg_categ="error" ) :
""" add an "error" arg to url slug """
slug_ = self.request.arguments
app_log.info("... add_error_message_to_slug / slug_ : \n %s ", pformat( slug_ ) )
# create a complete clean slug if no slug
if slug_ == {} :
error_slug = u"?" + u"error=" + tornado.escape.url_escape(error_string)
# add error arg to existing slug
else :
slug_without_error = deepcopy(slug_)
### clean existing slug from existing error arg if any
# for arg_to_delete in args_to_delete + DEFAULT_ERROR_ARGS_TO_DELETE :
# try :
# del slug_without_error[arg_to_delete]
# except :
# pass
slug_without_error = self.clean_slug(slug_without_error, args_to_delete + DEFAULT_ERROR_ARGS_TO_DELETE )
app_log.warning("... add_error_message_to_slug / slug_without_error : \n %s ", pformat(slug_without_error) )
# recreate slug
error_dict = { "error" : error_string }
error_dict.update( slug_without_error )
error_slug = u"?" + urllib.urlencode( error_dict, doseq=True)
app_log.info("... add_error_message_to_slug / error_slug : \n %s ", pformat(error_slug) )
return error_slug
示例8: check
def check(self, handler):
"""Check the rate limit for a handler.
Identifies the source by ip and user-agent.
If the rate limit is exceeded, raise HTTPError(429)
"""
if not self.limit:
return
key = self.key_for_handler(handler)
added = yield self.cache.add(key, 1, self.interval)
if not added:
# it's been seen before, use incr
try:
count = yield self.cache.incr(key)
except Exception as e:
app_log.warning("Failed to increment rate limit for %s", key)
return
app_log.debug("Rate limit remaining for %r: %s/%s", key, self.limit - count, self.limit)
if count and count >= self.limit:
minutes = self.interval // 60
raise HTTPError(429,
"Rate limit exceeded for {ip} ({limit} req / {minutes} min)."
" Try again later.".format(
ip=handler.request.remote_ip,
limit=self.limit,
minutes=minutes,
)
)
示例9: check_hub_user
def check_hub_user(self, user_model):
"""Check whether Hub-authenticated user should be allowed.
Returns the input if the user should be allowed, None otherwise.
Override if you want to check anything other than the username's presence in hub_users list.
Args:
user_model (dict): the user model returned from :class:`HubAuth`
Returns:
user_model (dict): The user model if the user should be allowed, None otherwise.
"""
if self.hub_users is None and self.hub_groups is None:
# no whitelist specified, allow any authenticated Hub user
return user_model
name = user_model['name']
if self.hub_users and name in self.hub_users:
# user in whitelist
return user_model
elif self.hub_groups and set(user_model['groups']).union(self.hub_groups):
# group in whitelist
return user_model
else:
app_log.warning("Not allowing Hub user %s" % name)
return None
示例10: get_company_exports_summary
def get_company_exports_summary(self, org_id):
db_ce = self.application.mysql_db_name("company-exports")
if not db_ce:
app_log.warning(
"Cannot add '%s' data. Database `%s` not online.",
"influence", db_ce)
return
data = {}
sql = """
select
{db_ce}.company.company_id,
count(distinct({db_ce}.action.destination_id))
from {db_ce}.action
join {db_ce}.company using (company_id)
where {db_ce}.company.caat_id = {caat_id}
;
""".format(**{
"db_ce": db_ce,
"caat_id": org_id
})
try:
result = self.orm.execute(sql).fetchone()
except InternalError as e:
print(e)
return
if result:
(company_id, n_dest, ) = result
data["companyExportsId"] = company_id
data["destinationCount"] = n_dest
sql = """
select
count(distinct({db_ce}.rating.description))
from {db_ce}.action
join {db_ce}.company using (company_id)
join {db_ce}.rating using (rating_id)
where {db_ce}.company.caat_id = {caat_id}
and {db_ce}.rating.description is not null
;
""".format(**{
"db_ce": db_ce,
"caat_id": org_id
})
try:
result = self.orm.execute(sql).fetchone()
except InternalError as e:
print(e)
return
if result:
(n_rating, ) = result
data["ratingCount"] = n_rating
return data
示例11: _get_user_cookie
def _get_user_cookie(self, handler):
token = handler.get_secure_cookie(self.cookie_name)
if token:
user_model = self.user_for_token(token)
if user_model is None:
app_log.warning("Token stored in cookie may have expired")
handler.clear_cookie(self.cookie_name)
return user_model
示例12: observe
def observe(self):
'''Collect Ground Truth of what's actually running from Docker and the proxy.'''
results = yield {
"docker": self.spawner.list_notebook_servers(self.name_pattern, all=True),
"proxy": self._proxy_routes()
}
self.container_ids = set()
self.living_container_ids = []
self.stopped_container_ids = []
self.zombie_container_ids = []
self.routes = set()
self.live_routes = []
self.stale_routes = []
self.zombie_routes = []
# Sort Docker results into living and dead containers.
for container in results["docker"]:
id = container['Id']
self.container_ids.add(id)
if container['Status'].startswith('Up'):
self.living_container_ids.append(id)
else:
self.stopped_container_ids.append(id)
now = datetime.utcnow()
idle_cutoff = now - self.cull_idle
started_cutoff = now - self.cull_max_age
# Sort proxy routes into living, stale, and zombie routes.
living_set = set(self.living_container_ids)
for path, route in results["proxy"].items():
last_activity_s = route.get('last_activity', None)
container_id = route.get('container_id', None)
if container_id:
result = (path, container_id)
if container_id in living_set:
try:
last_activity = datetime.strptime(last_activity_s, _date_fmt)
started = self.started.get(container_id, None)
self.routes.add(result)
if started and last_activity < idle_cutoff:
app_log.info("Culling %s, idle since %s", path, last_activity)
self.stale_routes.append(result)
elif started and started < started_cutoff:
app_log.info("Culling %s, up since %s", path, started)
self.stale_routes.append(result)
else:
app_log.debug("Container %s up since %s, idle since %s",
path, started, last_activity)
self.live_routes.append(result)
except ValueError as e:
app_log.warning("Ignoring a proxy route with an unparsable activity date: %s", e)
else:
# The container doesn't correspond to a living container.
self.zombie_routes.append(result)
示例13: _parse_json_arguments
def _parse_json_arguments(self):
content_type = self.content_type
if(content_type and content_type.find(r'application/json') >= 0):
try:
self.json_arguments = json_decode(self.request.body)
except Exception as error:
app_log.warning('Invalid application/json body: %s', error)
示例14: catch_error_message
def catch_error_message (self):
""" get and log error message if any """
try:
self.error_msg = self.get_argument("error")
app_log.warning("\n... get_error_message / self.error_msg : %s ", self.error_msg )
except:
self.error_msg = ""
示例15: _get_user_cookie
def _get_user_cookie(self, handler):
token = handler.get_secure_cookie(self.cookie_name)
session_id = self.get_session_id(handler)
if token:
token = token.decode('ascii', 'replace')
user_model = self.user_for_token(token, session_id=session_id)
if user_model is None:
app_log.warning("Token stored in cookie may have expired")
handler.clear_cookie(self.cookie_name)
return user_model