Try to resolve OAuth+JSON problems.

This is an attempt to solve issue #910 (and hopefully #896 by association).

This solution is unlikely to cause a regression except in one specific case, where the form data _is_ urlencoded but doesn't have the correct Content-Type header set. If we think that's a likely scenario, I can go back and make the test for that case less restrictive. The flip side is that we will not mistakenly include data we shouldn't.

There aren't any tests for OAuth functionality in Requests, so I have no idea if this makes things worse or better. My local tests seem to suggest that everything is ok though, so let's assume it's all awesome. =D

NB: I'm aware that we've moved the OAuth stuff to requests/requests-oauth. I'll raise an equivalent PR over there if we decide to use this one, but there are a few open issues here that make raising this PR here useful as well.

@idan: Does this look right to you?
@michaelhelmick: Does my branch resolve your issues?


I'll merge once @idan approves :)


Looks good to me!


:cake:


Hate to break it to ya, but this `0.14.2 dev` actually broke the first of my tests, just basic authenticating.

The app key and secret are part of a testing app, so feel free to use it, and you can change the callback to whatever.

``` python
app_key = 'RpN99dBp7nlTdVYotBDkag'
app_secret = 'qZzIwlI7qCU2MQyL8oYzZDdI976seimyskoxTFx0'

# Code
t = Twython(app_key=app_key,
            app_secret=app_secret,
            callback_url='http://michaelhelmick.com/')

auth_props = t.get_authentication_tokens()
print auth_props['auth_url']
```

Anyways, I run that code and this stacktrace:

```
Traceback (most recent call last):
  File "twython.py", line 585, in <module>
    auth_props = t.get_authentication_tokens()
  File "twython.py", line 274, in get_authentication_tokens
    raise TwythonAuthError("Seems something couldn't be verified with your OAuth junk. Error: %s, Message: %s" % (response.status_code, response.content))
__main__.TwythonAuthError: "Seems something couldn't be verified with your OAuth junk. Error: 401, Message: Failed to validate oauth signature and token"
```

If I run this code with `0.14.2 stable` everything works out fine and dandy. :sunflower: 


Blergh, my fail. Need to look at it when I get back to desk, may have run
tests with wrong branch

On Nov 26, 2012, at 19:13, Mike Helmick notifications@github.com wrote:

Hate to break it to ya, but this 0.14.2 dev actually broke the first of my
tests, just basic authenticating.

The app key and secret are part of a testing app, so feel free to use it,
and you can change the callback to whatever.

app_key = 'RpN99dBp7nlTdVYotBDkag'app_secret =
'qZzIwlI7qCU2MQyL8oYzZDdI976seimyskoxTFx0'

# Codet = Twython(app_key=app_key,

```
        app_secret=app_secret,
        callback_url='http://michaelhelmick.com/')
```

auth_props = t.get_authentication_tokens()print auth_props['auth_url']

Anyways, I run that code and this stacktrace:

Traceback (most recent call last):
  File "twython.py", line 585, in <module>
    auth_props = t.get_authentication_tokens()
  File "twython.py", line 274, in get_authentication_tokens
    raise TwythonAuthError("Seems something couldn't be verified with
your OAuth junk. Error: %s, Message: %s" % (response.status_code,
response.content))
**main**.TwythonAuthError: "Seems something couldn't be verified with
your OAuth junk. Error: 401, Message: Failed to validate oauth
signature and token"

If I run this code with 0.14.2 stable everything works out fine and
dandy. [image:
:sunflower:]

—
Reply to this email directly or view it on
GitHubhttps://github.com/kennethreitz/requests/pull/956#issuecomment-10724126.


I'm not that surprised that it broke. =(

When @idan can work out what the break is I'll open another PR to fix the issue.


Reverted for now, will revisit when I'm not bankrupt on time.


Remind me, merge conflict.