我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用web.internalerror()。
def main(): if "linux" in sys.platform: #root needed for writing files if os.geteuid() != 0: print("Need sudo for writing files") subprocess.call(['sudo', 'python', sys.argv[0]]) YA.get_youtube_service() YA.get_spreadsheet_service() web.internalerror = web.debugerror if internet(): t = index() t.daemon = True t.start() while True: try: sleep(100) except KeyboardInterrupt: print "\nQuitting Program" return else: return
def GET(self, params): result = None headers = self._get_headers() target_url = '/' +params if web.ctx.environ.get('QUERY_STRING', None): target_url += '?'+web.ctx.environ['QUERY_STRING'] httpcon = httplib.HTTPConnection('twitter.com', 80) try: httpcon.request('GET', target_url, headers=headers) twitter_response = httpcon.getresponse() return self.sendoutput(twitter_response) except Exception, inst: if result: logger.error("%s\n\n%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, web.data(), twitter_response.read())) else: logger.error("%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, web.data())) web.internalerror()
def POST(self, gateway, params): result = None if gateway not in picture_gateways: gateway = 'twitpic' ghost, gport, gbaseurl = picture_gateways[gateway] target_url = '/' +params headers = self._get_headers() httpcon = httplib.HTTPConnection(ghost, gport) #logger.debug(str(headers)) #logger.debug(web.data()) try: httpcon.request('POST', target_url, headers=headers, body=web.data()) twitter_response = httpcon.getresponse() return self.sendoutput(twitter_response) except Exception, inst: if result: logger.error("%s\n\n%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, web.data(), twitter_response.read())) else: logger.error("%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, web.data())) web.internalerror()
def POST(self, gateway, params): result = None if gateway not in picture_gateways: gateway = 'twitpic' ghost, gport, gbaseurl = picture_gateways[gateway] target_url = '/'+params headers = self._get_headers() httpcon = httplib.HTTPConnection(ghost, gport) #logger.debug(str(headers)) #logger.debug(web.data()) try: httpcon.request('POST', gbaseurl+'api/upload', headers=headers, body=web.data()) twitter_response = httpcon.getresponse() return self.sendoutput(twitter_response) except Exception, inst: if result: logger.error("%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, twitter_response.read())) else: logger.error("%s\n\n%s\n\n%s" % (target_url, str(inst), headers)) web.internalerror()
def internalerror(): return web.internalerror("Bad, bad server. No donut for you.")
def _setReturnCode(self, code): """Set the return code :param: code :type code: integer or string returns success: [True|False] """ success = False if code in (200, "200", "ok"): web.ok() success = True elif code in (201, "201", "created"): web.created() success = True elif code in (400, "400", "badrequest"): web.badrequest() elif code in (401, "401", "unauthorized"): web.unauthorized() elif code in (404, "404", "notfound"): web.notfound() elif code in (409, "409", "conflict"): web.conflict() elif code in (500, "500", "internalerror"): web.internalerror() elif code in (501, "501", "notimplemented"): # web.notimplemented() # not implemented # TODO - set 501 code manually web.internalerror() if success: logging.debug("[LayMan][_setReturnCode] Code: '%s'" % code) else: logging.error("[LayMan][_setReturnCode] Code: '%s'" % code) return success
def internalerror(): """Handle internal errors. Requires `app.internalerror = internalerror` following definition. """ return web.internalerror(render.error(500))
def internalerror(): # Compact traceback line etype, evalue, etb = sys.exc_info() fmt = "{0[0]}:{0[1]} ({0[2]}) -> {0[3]}" logstr = " | ".join(map(fmt.format, traceback.extract_tb(etb))) + " - " + etype.__name__ + ': "' + str(evalue) + '"' log.main.error(logstr) return web.internalerror(template.errors.generic("Something didn't load here and I logged it. Sorry for the inconvenience."))
def handler_internalerror(): return web.internalerror("server internal error")
def POST(self, params): result = None target_url = '/' +params headers = self._get_headers() httpcon = httplib.HTTPConnection('twitter.com', 80) try: httpcon.request('POST', target_url, headers=headers, body=web.data()) twitter_response = httpcon.getresponse() return self.sendoutput(twitter_response) except Exception, inst: if result: logger.error("%s\n\n%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, web.data(), twitter_response.read())) else: logger.error("%s\n\n%s\n\n%s\n\n%s" % (target_url, str(inst), headers, web.data())) web.internalerror()
def main(): """ Main setup function """ def urlr(exp): return virtual_root + exp + "/*" # Redirect workarounds if enabled if config.ini.getboolean("cgi", "redirect-workaround"): os.environ["SCRIPT_NAME"] = '' os.environ["REAL_SCRIPT_NAME"] = '' web.config.debug = config.ini.getboolean("cgi", "web-debug-mode") web.config.session_parameters["timeout"] = config.ini.getint("http", "session-timeout") web.config.session_parameters["cookie_name"] = config.ini.get("http", "session-cookie-name") if config.ini.getboolean("cgi", "fastcgi"): web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr) steam.api.key.set(config.ini.get("steam", "api-key")) # Cache file stuff cache_dir = config.ini.get("resources", "cache-dir") if not os.path.exists(cache_dir): os.makedirs(cache_dir) urls = ( virtual_root + "api", api_views.subapplication, urlr("inv/(?:user/)?(.+)"), "optf2.inventory_views.sim_selector", urlr(""), "optf2.views.index", urlr("about"), "optf2.views.about", urlr("(\w+)/items"), "optf2.schema_views.items", urlr("(\w+)/attributes/?(\d*)"), "optf2.schema_views.attributes", urlr("(\w+)/particles"), "optf2.schema_views.particles", urlr("(\w+)/item/(-?\d+)"), "optf2.inventory_views.item", urlr("(\w+)/item/(\w+)/(-?\d+)"), "optf2.inventory_views.live_item", urlr("(\w+)/loadout/(\w+)/?(\d*)"), "optf2.inventory_views.loadout", urlr("(\w+)/feed/(.+)"), "optf2.inventory_views.feed", urlr("(\w+)/(?:user/)?(.+)"), "optf2.inventory_views.fetch" ) application = web.application(urls, globals()) application.notfound = notfound if not config.ini.getboolean("cgi", "web-debug-mode"): application.internalerror = internalerror application.add_processor(web.loadhook(lang_hook)) application.add_processor(web.loadhook(motd_hook)) application.add_processor(web.loadhook(conf_hook)) return application