3 oauthlib.oauth1.rfc5849.errors
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 Error used both by OAuth 1 clients and provicers to represent the spec
7 defined error responses for all four core grant types.
9 from __future__ import unicode_literals
11 from oauthlib.common import urlencode, add_params_to_uri
14 class OAuth1Error(Exception):
18 def __init__(self, description=None, uri=None, status_code=400,
21 description: A human-readable ASCII [USASCII] text providing
22 additional information, used to assist the client
23 developer in understanding the error that occurred.
24 Values for the "error_description" parameter MUST NOT
25 include characters outside the set
26 x20-21 / x23-5B / x5D-7E.
28 uri: A URI identifying a human-readable web page with information
29 about the error, used to provide the client developer with
30 additional information about the error. Values for the
31 "error_uri" parameter MUST conform to the URI- Reference
32 syntax, and thus MUST NOT include characters outside the set
33 x21 / x23-5B / x5D-7E.
35 state: A CSRF protection value received from the client.
37 request: Oauthlib Request object
39 self.description = description or self.description
40 message = '(%s) %s' % (self.error, self.description)
42 message += ' ' + repr(request)
43 super(OAuth1Error, self).__init__(message)
46 self.status_code = status_code
48 def in_uri(self, uri):
49 return add_params_to_uri(uri, self.twotuples)
53 error = [('error', self.error)]
55 error.append(('error_description', self.description))
57 error.append(('error_uri', self.uri))
62 return urlencode(self.twotuples)
65 class InsecureTransportError(OAuth1Error):
66 error = 'insecure_transport_protocol'
67 description = 'Only HTTPS connections are permitted.'
70 class InvalidSignatureMethodError(OAuth1Error):
71 error = 'invalid_signature_method'
74 class InvalidRequestError(OAuth1Error):
75 error = 'invalid_request'
78 class InvalidClientError(OAuth1Error):
79 error = 'invalid_client'