Fix Content-Type validation in OAuth1 callable
authorIdan Gazit <idan@gazit.me>
Sun, 22 Apr 2012 11:39:29 +0000 (14:39 +0300)
committerDonald Stufft <donald.stufft@gmail.com>
Tue, 1 May 2012 10:20:52 +0000 (06:20 -0400)
requests/auth.py

index f4a885adc8446a218cd5423d8571ff4b3c3fb3f5..18d6318ce9811f3c9741c0e29687014b660acc79 100644 (file)
@@ -46,8 +46,9 @@ class OAuth1(AuthBase):
             signature_type, rsa_key, verifier)
 
     def __call__(self, r):
+        contenttype = r.headers.get('Content-Type')
         if (r.files or
-            r.headers['Content-Type'] != 'application/x-www-form-urlencoded'):
+            (contenttype and contenttype != 'application/x-www-form-urlencoded')):
 
             # XXX TODO can we use body signatures with a non formencoded body?
             if self.client.signature_type == SIGNATURE_TYPE_BODY:
@@ -59,7 +60,7 @@ class OAuth1(AuthBase):
             alter_body = False  # we shouldn't touch the body
         else:
             body = r.data  # OAuthLib is cool with both strings and dicts.
-            if isinstance(str, body):
+            if isinstance(body, str):
                 # XXX gross hack. We must pass unicode...
                 body = unicode(body, 'utf-8')
             alter_body = True