Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 18, 2012
@xrg xrg oauth: narrow on exception handling
It is generally not advisable to use "except:" in python, because it would
catch "KeyboardInterrupt" and "SystemExit", meant only to be caught at
main() level. Only catch the ones we really expect to see, let others
propagate up the stack.

Also, when computing the HMAC, we shall not retry w/o hashlib in the case
that first hashing has gone wrong. This confuses the error message between
a missing import and a bad supplied hash.
Commits on Apr 28, 2012
@leah Merge pull request #3 from xrg/xrg
oauth: narrow on exception handling
Showing with 8 additions and 8 deletions.
  1. +8 −8 oauth/
16 oauth/
@@ -183,7 +183,7 @@ def set_parameter(self, parameter, value):
def get_parameter(self, parameter):
return self.parameters[parameter]
- except:
+ except KeyError:
raise OAuthError('Parameter not found: %s' % parameter)
def _get_timestamp_nonce(self):
@@ -224,7 +224,7 @@ def get_normalized_parameters(self):
# Exclude the signature if it exists.
del params['oauth_signature']
- except:
+ except KeyError:
# Escape key values before sorting.
key_values = [(escape(_utf8_str(k)), escape(_utf8_str(v))) \
@@ -278,7 +278,7 @@ def from_request(http_method, http_url, headers=None, parameters=None,
# Get the parameters from the header.
header_params = OAuthRequest._split_header(auth_header)
- except:
+ except Exception:
raise OAuthError('Unable to parse OAuth parameters from '
'Authorization header.')
@@ -450,7 +450,7 @@ def _get_version(self, oauth_request):
"""Verify the correct version request for this server."""
version = oauth_request.get_parameter('oauth_version')
- except:
+ except Exception:
version = VERSION
if version and version != self.version:
raise OAuthError('OAuth version %s not supported.' % str(version))
@@ -461,12 +461,12 @@ def _get_signature_method(self, oauth_request):
signature_method = oauth_request.get_parameter(
- except:
+ except Exception:
signature_method = SIGNATURE_METHOD
# Get the signature method object.
signature_method = self.signature_methods[signature_method]
- except:
+ except KeyError:
signature_method_names = ', '.join(self.signature_methods.keys())
raise OAuthError('Signature method %s not supported try one of the '
'following: %s' % (signature_method, signature_method_names))
@@ -498,7 +498,7 @@ def _check_signature(self, oauth_request, consumer, token):
signature_method = self._get_signature_method(oauth_request)
signature = oauth_request.get_parameter('oauth_signature')
- except:
+ except Exception:
raise OAuthError('Missing signature.')
# Validate the signature.
valid_sig = signature_method.check_signature(oauth_request, consumer,
@@ -629,7 +629,7 @@ def build_signature(self, oauth_request, consumer, token):
import hashlib # 2.5
hashed =, raw, hashlib.sha1)
- except:
+ except ImportError:
import sha # Deprecated
hashed =, raw, sha)

No commit comments for this range

Something went wrong with that request. Please try again.