diff --git a/keystone/common/sql/core.py b/keystone/common/sql/core.py index 27df89145d..44d69217f3 100644 --- a/keystone/common/sql/core.py +++ b/keystone/common/sql/core.py @@ -119,9 +119,9 @@ class MySQLPingListener(object): def checkout(self, dbapi_con, con_record, con_proxy): try: dbapi_con.cursor().execute('select 1') - except dbapi_con.OperationalError, ex: - if ex.args[0] in (2006, 2013, 2014, 2045, 2055): - logging.warn('Got mysql server has gone away: %s', ex) + except dbapi_con.OperationalError as e: + if e.args[0] in (2006, 2013, 2014, 2045, 2055): + logging.warn('Got mysql server has gone away: %s', e) raise DisconnectionError("Database server went away") else: raise diff --git a/keystone/middleware/auth_token.py b/keystone/middleware/auth_token.py index e8ed99b345..cd9b806605 100644 --- a/keystone/middleware/auth_token.py +++ b/keystone/middleware/auth_token.py @@ -286,7 +286,7 @@ class AuthProtocol(object): LOG.info('Invalid user token - rejecting request') return self._reject_request(env, start_response) - except ServiceError, e: + except ServiceError as e: LOG.critical('Unable to obtain admin token: %s' % e) resp = webob.exc.HTTPServiceUnavailable() return resp(env, start_response) @@ -378,7 +378,7 @@ class AuthProtocol(object): conn.request(method, path) response = conn.getresponse() body = response.read() - except Exception, e: + except Exception as e: LOG.error('HTTP connection exception: %s' % e) raise ServiceError('Unable to communicate with keystone') finally: @@ -418,7 +418,7 @@ class AuthProtocol(object): conn.request(method, full_path, **kwargs) response = conn.getresponse() body = response.read() - except Exception, e: + except Exception as e: LOG.error('HTTP connection exception: %s' % e) raise ServiceError('Unable to communicate with keystone') finally: diff --git a/keystone/middleware/core.py b/keystone/middleware/core.py index 6f8abff2a4..a49f743be4 100644 --- a/keystone/middleware/core.py +++ b/keystone/middleware/core.py @@ -147,7 +147,7 @@ class XmlBodyMiddleware(wsgi.Middleware): try: body_obj = jsonutils.loads(response.body) response.body = serializer.to_xml(body_obj) - except: + except Exception: raise exception.Error(message=response.body) return response diff --git a/keystone/middleware/s3_token.py b/keystone/middleware/s3_token.py index 7cf2e3944d..0f207b3d8b 100644 --- a/keystone/middleware/s3_token.py +++ b/keystone/middleware/s3_token.py @@ -99,7 +99,7 @@ class S3Token(object): headers=headers) response = conn.getresponse() output = response.read() - except Exception, e: + except Exception as e: self.logger.info('HTTP connection exception: %s' % e) resp = self.deny_request('InvalidURI') raise ServiceError(resp) @@ -143,7 +143,7 @@ class S3Token(object): auth_header = req.headers['Authorization'] try: access, signature = auth_header.split(' ')[-1].rsplit(':', 1) - except(ValueError): + except ValueError: msg = 'You have an invalid Authorization header: %s' self.logger.debug(msg % (auth_header)) return self.deny_request('InvalidURI')(environ, start_response) diff --git a/tests/test_content_types.py b/tests/test_content_types.py index 95d1256abb..67565207b8 100644 --- a/tests/test_content_types.py +++ b/tests/test_content_types.py @@ -258,10 +258,6 @@ class RestfulTestCase(test.TestCase): class CoreApiTests(object): def assertValidError(self, error): """Applicable to XML and JSON.""" - try: - print error.attrib - except: - pass self.assertIsNotNone(error.get('code')) self.assertIsNotNone(error.get('title')) self.assertIsNotNone(error.get('message')) diff --git a/tests/test_serializer.py b/tests/test_serializer.py index 0a4ff66b72..288e551694 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -29,7 +29,7 @@ class XmlSerializerTestCase(test.TestCase): """ try: self.assertEqual(a, b) - except: + except AssertionError: a = re.sub('[ \n]+', ' ', a).strip().split() b = re.sub('[ \n]+', ' ', b).strip().split() self.assertEqual(a, b)