Python httplib.INTERNAL_SERVER_ERROR Examples
The following are 30
code examples of httplib.INTERNAL_SERVER_ERROR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
httplib
, or try the search function
.
Example #1
Source File: experiments.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def capture_exception(callback, request, url_parts): """ execute `callback` with `request` and `path_parts` parameters and handles exceptions generated from `callback` Args: callback (function): the callback function to execute request ([type]): the request object being passed in from rest handler path_parts ([type]): the url parts passed in from rest handler Returns: dict """ try: return callback(request, url_parts) except (SplunkRestProxyException, SplunkRestException) as e: return e.to_http_response() except Exception as e: return SplunkRestProxyException('Can not complete the request: %s' % str(e), logging.ERROR, httplib.INTERNAL_SERVER_ERROR).to_http_response()
Example #2
Source File: blockables.py From upvote with Apache License 2.0 | 6 votes |
def post(self, blockable_id): # pylint: disable=g-bad-name """Post handler for blockables.""" blockable_id = blockable_id.lower() logging.info('Blockable handler POST input: %s', self.request.arguments()) if self.request.get('recount').lower() == 'recount': try: voting_api.Recount(blockable_id) except voting_api.BlockableNotFoundError: self.abort(httplib.NOT_FOUND, explanation='Blockable not found') except voting_api.UnsupportedClientError: self.abort(httplib.BAD_REQUEST, explanation='Unsupported client') except Exception as e: # pylint: disable=broad-except self.abort(httplib.INTERNAL_SERVER_ERROR, explanation=e.message) else: blockable = binary_models.Blockable.get_by_id(blockable_id) self.respond_json(blockable) elif self.request.get('reset').lower() == 'reset': self._reset_blockable(blockable_id) else: self._insert_blockable(blockable_id, datetime.datetime.utcnow())
Example #3
Source File: exemptions.py From upvote with Apache License 2.0 | 6 votes |
def post(self, host_id): if not self.exm: self.abort(httplib.NOT_FOUND, explanation='Exemption not found') # Extract and validate POST data fields. justification = self.request.get('justification') if not justification: self.abort( httplib.BAD_REQUEST, explanation='No justification for revoking exemption provided') try: exemption_api.Revoke(self.exm.key, [justification]) except Exception: # pylint: disable=broad-except logging.exception( 'Error encountered while revoking Exemption for host %s', host_id) self.abort( httplib.INTERNAL_SERVER_ERROR, explanation='Error while revoking exemption') self._RespondWithExemptionAndTransitiveState(self.exm.key)
Example #4
Source File: end_to_end_test.py From JediHTTP with Apache License 2.0 | 6 votes |
def test_client_bad_request_with_parameters(jedihttp): filepath = utils.fixture_filepath('goto.py') request_data = { 'source': read_file(filepath), 'line': 100, 'col': 1, 'source_path': filepath } response = requests.post( 'http://127.0.0.1:{0}/gotodefinition'.format(PORT), json=request_data, auth=HmacAuth(SECRET)) assert_that(response.status_code, equal_to(httplib.INTERNAL_SERVER_ERROR)) hmachelper = hmaclib.JediHTTPHmacHelper(SECRET) assert_that(hmachelper.is_response_authenticated(response.headers, response.content))
Example #5
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_Exception(self, mock_approve): with self.LoggedInUser(admin=True): params = {'justification': 'I want to'} self.testapp.post( self.ROUTE % self.host_id, params, status=httplib.INTERNAL_SERVER_ERROR) self.assertEqual( constants.EXEMPTION_STATE.ESCALATED, self.exm_key.get().state) mock_approve.assert_called_once()
Example #6
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_Exception(self, mock_escalate): with self.LoggedInUser(user=self.user): self.testapp.post( self.ROUTE % self.host_id, status=httplib.INTERNAL_SERVER_ERROR)
Example #7
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_Exception(self, mock_deny): with self.LoggedInUser(admin=True): params = {'justification': 'I want to'} self.testapp.post( self.ROUTE % self.host_id, params, status=httplib.INTERNAL_SERVER_ERROR) self.assertEqual( constants.EXEMPTION_STATE.ESCALATED, self.exm_key.get().state) mock_deny.assert_called_once() self.assertNoBigQueryInsertions()
Example #8
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_Exception(self, mock_revoke): with self.LoggedInUser(admin=True): params = {'justification': 'I want to'} self.testapp.post( self.ROUTE % self.host_id, params, status=httplib.INTERNAL_SERVER_ERROR) self.assertEqual( constants.EXEMPTION_STATE.APPROVED, self.exm_key.get().state) mock_revoke.assert_called_once() self.assertNoBigQueryInsertions()
Example #9
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_Exception(self, mock_cancel): with self.LoggedInUser(user=self.valid_user): self.testapp.post( self.ROUTE % self.host_id, status=httplib.INTERNAL_SERVER_ERROR) mock_cancel.assert_called_once() self.assertEqual( constants.EXEMPTION_STATE.APPROVED, self.exm_key.get().state) self.assertNoBigQueryInsertions()
Example #10
Source File: votes_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_NoRolesError(self, mock_highest_role): mock_highest_role.side_effect = user_models.NoRolesError user = test_utils.CreateUser() self.assertIsNone(user.last_vote_dt) with self.LoggedInUser(user=user): self.testapp.post( self.ROUTE % test_utils.RandomSHA256(), status=httplib.INTERNAL_SERVER_ERROR) self.assertIsNone(user.last_vote_dt)
Example #11
Source File: votes.py From upvote with Apache License 2.0 | 5 votes |
def post(self, blockable_id): """Handle votes from users.""" was_yes_vote = (self.request.get('wasYesVote') == 'true') role = self.request.get('asRole', default_value=self.user.highest_role) vote_weight = self._GetVoteWeight(role) logging.info( 'User %s is using the %s role to cast a %s%s vote for %s', self.user.nickname, role, '+' if was_yes_vote else '-', vote_weight, blockable_id) try: vote = voting_api.Vote(self.user, blockable_id, was_yes_vote, vote_weight) except voting_api.BlockableNotFoundError: self.abort(httplib.NOT_FOUND, explanation='Application not found') except voting_api.UnsupportedClientError: self.abort(httplib.BAD_REQUEST, explanation='Unsupported client') except voting_api.InvalidVoteWeightError: self.abort(httplib.BAD_REQUEST, explanation='Invalid voting weight') except voting_api.DuplicateVoteError: self.abort(httplib.CONFLICT, explanation='Vote already exists') except voting_api.OperationNotAllowedError as e: self.abort(httplib.FORBIDDEN, explanation=e.message) except Exception as e: # pylint: disable=broad-except self.abort(httplib.INTERNAL_SERVER_ERROR, explanation=e.message) else: # Update the user's last vote date self.user.last_vote_dt = datetime.datetime.utcnow() self.user.put() # Augment the response dict with related voting data. blockable = binary_models.Blockable.get_by_id(blockable_id) blockable_dict = blockable.to_dict() allowed, reason = voting_api.IsVotingAllowed(blockable.key) blockable_dict['is_voting_allowed'] = allowed blockable_dict['voting_prohibited_reason'] = reason self.respond_json({'blockable': blockable_dict, 'vote': vote})
Example #12
Source File: blockables.py From upvote with Apache License 2.0 | 5 votes |
def _reset_blockable(self, blockable_id): logging.info('Blockable reset: %s', blockable_id) try: voting_api.Reset(blockable_id) except voting_api.BlockableNotFoundError: self.abort(httplib.NOT_FOUND) except voting_api.UnsupportedClientError: self.abort(httplib.BAD_REQUEST, explanation='Unsupported client') except voting_api.OperationNotAllowedError as e: self.abort(httplib.FORBIDDEN, explanation=e.message) except Exception as e: # pylint: disable=broad-except self.abort(httplib.INTERNAL_SERVER_ERROR, explanation=e.message) else: blockable = binary_models.Blockable.get_by_id(blockable_id) self.respond_json(blockable)
Example #13
Source File: exemptions.py From upvote with Apache License 2.0 | 5 votes |
def post(self, host_id): if not self.exm: self.abort(httplib.NOT_FOUND, explanation='Exemption not found') # Humans should never trigger the transition from PENDING to APPROVED, only # api.Process() should. if self.exm.key.get().state == constants.EXEMPTION_STATE.PENDING: self.abort( httplib.FORBIDDEN, explanation='Cannot approve a pending request') # Extract and validate POST data fields. justification = self.request.get('justification') if not justification: self.abort( httplib.BAD_REQUEST, explanation='No justification for approval provided') try: exemption_api.Approve(self.exm.key, details=[justification]) except Exception: # pylint: disable=broad-except logging.exception( 'Error encountered while approving Exemption for host %s', host_id) self.abort( httplib.INTERNAL_SERVER_ERROR, explanation='Error while approving exemption') self._RespondWithExemptionAndTransitiveState(self.exm.key)
Example #14
Source File: exemptions.py From upvote with Apache License 2.0 | 5 votes |
def post(self, host_id): if not self.exm: self.abort(httplib.NOT_FOUND, explanation='Exemption not found') # Humans should never trigger the transition from PENDING to DENIED, only # api.Process() should. if self.exm.key.get().state == constants.EXEMPTION_STATE.PENDING: self.abort(httplib.FORBIDDEN, explanation='Cannot deny a pending request') justification = self.request.get('justification') if not justification: self.abort( httplib.BAD_REQUEST, explanation='No justification for denial provided') try: exemption_api.Deny(self.exm.key, details=[justification]) except Exception: # pylint: disable=broad-except logging.exception( 'Error encountered while denying Exemption for host %s', host_id) self.abort( httplib.INTERNAL_SERVER_ERROR, explanation='Error while denying exemption') self.respond_json(self.exm.key.get())
Example #15
Source File: exemptions.py From upvote with Apache License 2.0 | 5 votes |
def post(self, host_id): if not self.exm: self.abort(httplib.NOT_FOUND, explanation='Exemption not found') # Verify that the current user is associated with the Host. # NOTE: Admins don't get a pass here, they can (and should) use the # above 'revoke' handler instead. if not model_utils.IsHostAssociatedWithUser(self.host, self.user): logging.error( 'Host %s not associated with user %s', host_id, self.user.nickname) self.abort( httplib.FORBIDDEN, explanation='Host not associated with requesting user') try: exemption_api.Cancel(self.exm.key) except Exception: # pylint: disable=broad-except logging.exception( 'Error encountered while cancelling Exemption for host %s', host_id) self.abort( httplib.INTERNAL_SERVER_ERROR, explanation='Failed to cancel exemption') self._RespondWithExemptionAndTransitiveState(self.exm.key) # The Webapp2 routes defined for these handlers.
Example #16
Source File: blockables_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_Admin_Recount_Exception(self, mock_recount): with self.LoggedInUser(admin=True): self.testapp.post( self.ROUTE % test_utils.RandomSHA256(), params={'recount': 'recount'}, status=httplib.INTERNAL_SERVER_ERROR)
Example #17
Source File: handler_utils_test.py From upvote with Apache License 2.0 | 5 votes |
def testHandleException_ApplicationError(self, mock_get): response = self.testapp.get('/', expect_errors=True) self.assertEqual(httplib.INTERNAL_SERVER_ERROR, response.status_int) self.assertEqual(1, mock_get.call_count)
Example #18
Source File: handler_utils.py From upvote with Apache License 2.0 | 5 votes |
def handle_exception(self, exception, unused_debug_mode): """Handle any uncaught exceptions. Args: exception: The exception that was thrown. unused_debug_mode: True if the application is running in debug mode. """ # Default to a 500. http_status = httplib.INTERNAL_SERVER_ERROR # Calls to abort() raise a child class of HTTPException, so extract the # HTTP status and explanation if possible. if isinstance(exception, webapp2.HTTPException): http_status = getattr(exception, 'code', httplib.INTERNAL_SERVER_ERROR) # Write out the exception's explanation to the response body escaped_explanation = _HtmlEscape(str(exception)) self.response.write(escaped_explanation) # If the RequestHandler has a corresponding request counter, increment it. if self.RequestCounter is not None: self.RequestCounter.Increment(http_status) # If the exception occurs within a unit test, make sure the stacktrace is # easily discerned from the console. if not env_utils.RunningInProd(): exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) # Set the response code and log the exception regardless. self.response.set_status(http_status) logging.exception(exception)
Example #19
Source File: handler_utils.py From upvote with Apache License 2.0 | 5 votes |
def respond_json(self, response_data): try: response_json = self.json_encoder.encode(response_data) except TypeError as e: logging.error('Failed to serialize JSON response: %s', e) self.abort(httplib.INTERNAL_SERVER_ERROR, 'Failed to serialize response') else: self.response.content_type = 'application/json' self.response.write(response_json)
Example #20
Source File: role_syncing.py From upvote with Apache License 2.0 | 5 votes |
def _GetAllUntrustedUsers(self, group_client, untrusted_group_names): untrusted_users = set() for untrusted_group_name in untrusted_group_names: # Make sure the untrusted group actually exists first. if not group_client.DoesGroupExist(untrusted_group_name): logging.error('Untrusted group %s does not exist', untrusted_group_name) self.abort(httplib.INTERNAL_SERVER_ERROR) untrusted_users |= set(group_client.AllMembers(untrusted_group_name)) return frozenset(untrusted_users)
Example #21
Source File: datastore_backup_test.py From upvote with Apache License 2.0 | 5 votes |
def testException(self, mock_prod, mock_env, mock_fetch): mock_fetch.side_effect = urlfetch.Error self.testapp.get( self.ROUTE, headers={'X-AppEngine-Cron': 'true'}, status=httplib.INTERNAL_SERVER_ERROR) self.mock_metric.Increment.assert_not_called()
Example #22
Source File: client.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def __call__(self, *args, **kwargs): """Invoke the method.""" clientclass = self.clientclass(kwargs) client = clientclass(self.client, self.method) try: return client.invoke(args, kwargs) except WebFault, e: if self.faults(): raise return httplib.INTERNAL_SERVER_ERROR, e
Example #23
Source File: common.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def showHttpErrorCodes(): """ Shows all HTTP error codes raised till now """ if kb.httpErrorCodes: warnMsg = "HTTP error codes detected during run:\n" warnMsg += ", ".join("%d (%s) - %d times" % (code, httplib.responses[code] if code in httplib.responses else '?', count) for code, count in kb.httpErrorCodes.items()) logger.warn(warnMsg) if any((str(_).startswith('4') or str(_).startswith('5')) and _ != httplib.INTERNAL_SERVER_ERROR and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()): msg = "too many 4xx and/or 5xx HTTP error codes " msg += "could mean that some kind of protection is involved (e.g. WAF)" logger.debug(msg)
Example #24
Source File: stackdriver_handlers.py From spinnaker-monitoring with Apache License 2.0 | 5 votes |
def process_web_request(self, request, path, params, fragment): """Implements CommandHandler.""" options = dict(get_global_options()) options.update(params) if str(params.get('clear_all')).lower() != 'true': stackdriver = stackdriver_service.make_service(options) audit_results = stackdriver_descriptors.AuditResults(stackdriver) descriptor_list = audit_results.descriptor_map.values() descriptor_html = '\n<li> '.join(item['type'] for item in descriptor_list) html = textwrap.dedent("""\ Clearing descriptors requires query parameter <code>clear_all=true</code>. <p/> Here are the {count} custom descriptors: <ul> <li>{descriptors} </ul> <p/> <a href="{path}?clear_all=true">Yes, delete everything!</a> """.format(count=len(descriptor_list), descriptors=descriptor_html, path=path)) html_doc = http_server.build_html_document( html, title='Missing Parameters') request.respond( 400, {'ContentType': 'text/html'}, html_doc) return audit_results = self.__do_clear(options) response_code = (httplib.OK if audit_results.obsoleted_count == 0 else httplib.INTERNAL_SERVER_ERROR) headers = {'Content-Type': 'text/plain'} body = audit_results_to_output( audit_results, "No custom descriptors to delete.") request.respond(response_code, headers, body)
Example #25
Source File: dsss.py From leviathan with GNU General Public License v3.0 | 5 votes |
def scan_page(url, data=None): retval, usable = False, False url, data = re.sub(r"=(&|\Z)", "=1\g<1>", url) if url else url, re.sub(r"=(&|\Z)", "=1\g<1>", data) if data else data try: for phase in (GET, POST): original, current = None, url if phase is GET else (data or "") for match in re.finditer(r"((\A|[?&])(?P<parameter>[^_]\w*)=)(?P<value>[^&#]+)", current): vulnerable, usable = False, True #print "* scanning %s parameter '%s'" % (phase, match.group("parameter")) original = original or (_retrieve_content(current, data) if phase is GET else _retrieve_content(url, current)) tampered = current.replace(match.group(0), "%s%s" % (match.group(0), urllib.quote("".join(random.sample(TAMPER_SQL_CHAR_POOL, len(TAMPER_SQL_CHAR_POOL)))))) content = _retrieve_content(tampered, data) if phase is GET else _retrieve_content(url, tampered) for (dbms, regex) in ((dbms, regex) for dbms in DBMS_ERRORS for regex in DBMS_ERRORS[dbms]): if not vulnerable and re.search(regex, content[HTML], re.I) and not re.search(regex, original[HTML], re.I): #print " (i) %s parameter '%s' appears to be error SQLi vulnerable (%s)" % (phase, match.group("parameter"), dbms) print url retval = vulnerable = True vulnerable = False for prefix, boolean, suffix, inline_comment in itertools.product(PREFIXES, BOOLEAN_TESTS, SUFFIXES, (False, True)): if not vulnerable: template = ("%s%s%s" % (prefix, boolean, suffix)).replace(" " if inline_comment else "/**/", "/**/") payloads = dict((_, current.replace(match.group(0), "%s%s" % (match.group(0), urllib.quote(template % (RANDINT if _ else RANDINT + 1, RANDINT), safe='%')))) for _ in (True, False)) contents = dict((_, _retrieve_content(payloads[_], data) if phase is GET else _retrieve_content(url, payloads[_])) for _ in (False, True)) if all(_[HTTPCODE] and _[HTTPCODE] < httplib.INTERNAL_SERVER_ERROR for _ in (original, contents[True], contents[False])): if any(original[_] == contents[True][_] != contents[False][_] for _ in (HTTPCODE, TITLE)): vulnerable = True else: ratios = dict((_, difflib.SequenceMatcher(None, original[TEXT], contents[_][TEXT]).quick_ratio()) for _ in (False, True)) vulnerable = all(ratios.values()) and min(ratios.values()) < FUZZY_THRESHOLD < max(ratios.values()) and abs(ratios[True] - ratios[False]) > FUZZY_THRESHOLD / 10 if vulnerable: #print " (i) %s parameter '%s' appears to be blind SQLi vulnerable (e.g.: '%s')" % (phase, match.group("parameter"), payloads[True]) print url retval = True except KeyboardInterrupt: pass return retval
Example #26
Source File: common.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def showHttpErrorCodes(): """ Shows all HTTP error codes raised till now """ if kb.httpErrorCodes: warnMsg = "HTTP error codes detected during run:\n" warnMsg += ", ".join("%d (%s) - %d times" % (code, httplib.responses[code] \ if code in httplib.responses else '?', count) \ for code, count in kb.httpErrorCodes.items()) logger.warn(warnMsg) if any((str(_).startswith('4') or str(_).startswith('5')) and _ != httplib.INTERNAL_SERVER_ERROR and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()): msg = "too many 4xx and/or 5xx HTTP error codes " msg += "could mean that some kind of protection is involved (e.g. WAF)" logger.debug(msg)
Example #27
Source File: cloud_datastore_export_test.py From loaner with Apache License 2.0 | 5 votes |
def test_get_urlfetch_error(self, mock_config, mock_urlfetch): mock_config.side_effect = ['gcp_bucket_name', True] response = self.testapp.get(self._CRON_URL, expect_errors=True) self.assertEqual(response.status_int, httplib.INTERNAL_SERVER_ERROR)
Example #28
Source File: dev_appserver.py From browserscope with Apache License 2.0 | 5 votes |
def ReadDataFile(data_path, openfile=file): """Reads a file on disk, returning a corresponding HTTP status and data. Args: data_path: Path to the file on disk to read. openfile: Used for dependency injection. Returns: Tuple (status, data) where status is an HTTP response code, and data is the data read; will be an empty string if an error occurred or the file was empty. """ status = httplib.INTERNAL_SERVER_ERROR data = "" try: data_file = openfile(data_path, 'rb') try: data = data_file.read() finally: data_file.close() status = httplib.OK except (OSError, IOError), e: logging.error('Error encountered reading file "%s":\n%s', data_path, e) if e.errno in FILE_MISSING_EXCEPTIONS: status = httplib.NOT_FOUND else: status = httplib.FORBIDDEN
Example #29
Source File: dev_appserver_multiprocess.py From browserscope with Apache License 2.0 | 5 votes |
def handle_one_request(self): """Override. Invoked from BaseHTTPRequestHandler constructor.""" self.raw_requestline = self.rfile.readline() if not self.raw_requestline: self.close_connection = 1 return if not self.parse_request(): return process = GlobalProcess() balance_set = process.GetBalanceSet() request_size = int(self.headers.get('content-length', 0)) payload = self.rfile.read(request_size) for port in balance_set: logging.debug('balancer to port %d', port) connection = self.connection_handler(process.host, port=port) connection.response_class = ForwardResponse connection.request(self.command, self.path, payload, dict(self.headers)) try: response = connection.getresponse() except httplib.HTTPException, e: self.send_error(httplib.INTERNAL_SERVER_ERROR, str(e)) return if response.status != httplib.SERVICE_UNAVAILABLE: self.wfile.write(response.data) return
Example #30
Source File: wsgi.py From endpoints-management-python with Apache License 2.0 | 5 votes |
def __init__(self): self.api_key_valid = True self.response_code = httplib.INTERNAL_SERVER_ERROR self.response_size = report_request.NOT_SET self.request_size = report_request.NOT_SET self.http_method = None self.url = None