Permalink
Browse files

Unicodified the responses received from httplib2.

Fixes #135
  • Loading branch information...
1 parent 0275faf commit 7ae299ef86c9f58ae35de511142473a552ba8d5c @flashingpumpkin committed Jan 18, 2012
Showing with 14 additions and 4 deletions.
  1. +14 −4 socialregistration/clients/oauth.py
@@ -1,3 +1,4 @@
+from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
from socialregistration.clients import Client
import httplib2
@@ -85,12 +86,15 @@ def _get_request_token(self):
'oauth_callback': self.get_callback_url()
}
+
response, content = self.client().request(self.request_token_url,
"POST", body=urllib.urlencode(params))
+ content = smart_unicode(content)
+
if not response['status'] == '200':
raise OAuthError(_(
- "Invalid status code %s while obtaining request token from %s: %s") % (
+ u"Invalid status code %s while obtaining request token from %s: %s") % (
response['status'], self.request_token_url, content))
token = dict(urlparse.parse_qsl(content))
@@ -105,9 +109,11 @@ def _get_access_token(self, verifier=None):
response, content = self.client(verifier).request(
self.access_token_url, "POST")
+ content = smart_unicode(content)
+
if not response['status'] == '200':
raise OAuthError(_(
- "Invalid status code %s while obtaining access token from %s: %s") %
+ u"Invalid status code %s while obtaining access token from %s: %s") %
(response['status'], self.access_token_url, content))
token = dict(urlparse.parse_qsl(content))
@@ -169,9 +175,11 @@ def request(self, url, method="GET", params=None, headers=None):
response, content = self.client().request(url, method, headers=headers,
body=urllib.urlencode(params))
+ content = smart_unicode(content)
+
if response['status'] != '200':
raise OAuthError(_(
- "Invalid status code %s while requesting %s: %s") % (
+ u"Invalid status code %s while requesting %s: %s") % (
response['status'], url, content))
return content
@@ -254,11 +262,13 @@ def _get_access_token(self, code, **params):
resp, content = self.request_access_token(params=params)
+ content = smart_unicode(content)
+
content = self.parse_access_token(content)
if 'error' in content:
raise OAuthError(_(
- "Received error while obtaining access token from %s: %s") % (
+ u"Received error while obtaining access token from %s: %s") % (
self.access_token_url, content['error']))
return content

0 comments on commit 7ae299e

Please sign in to comment.