Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: oauth_problem=permission_unknown #8

Open
rubinovitz opened this issue Jun 27, 2014 · 14 comments

Comments

@rubinovitz
Copy link
Contributor

I'm redirecting to the url given by .get_authorization_url() and getting an oauth_token and oauth_verifier back, but when I try to send the oauth_verifier through .get_access_tokens() I get the following rauth error:

KeyError: 'Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: oauth_problem=permission_unknown'

Does anyone know what's up?

@simonv3
Copy link
Owner

simonv3 commented Jul 23, 2014

Hey @rubinovitz, sorry I didn't get back to you on this earlier - did you ever sort this out?

I remember regularly having issues with Quickbooks and permissions. Once in a while it would just shut down on me. I'll have a look at my own code and see if I can reproduce this.

@rubinovitz
Copy link
Contributor Author

Haven't found a fix so far.

On Wed, Jul 23, 2014 at 7:33 AM, Simon [email protected] wrote:

Hey @rubinovitz https://github.com/rubinovitz, sorry I didn't get back
to you on this earlier - did you ever sort this out?

I remember regularly having issues with Quickbooks and permissions. Once
in a while it would just shut down on me. I'll have a look at my own code
and see if I can reproduce this.


Reply to this email directly or view it on GitHub
#8 (comment)
.

Jennifer Rubinovitz

@simonv3
Copy link
Owner

simonv3 commented Jul 24, 2014

Okay, I've been able to create that same error message, and I will freely admit that how I deal with this step myself feels like a hack.

So, I get this error message when I do this:

set up qb_object
set up a qb_service #(via the get_authorize_url method)
# url redirects to the same function
set up a qb_object # (new request token & secret)
set up a *new* qb_service # (via the get_authorize_url method) <-- !! this means that you now have a different service
>> throws error

What's happening in my case is that the service I set up to create the request, is no longer the same service one. Have a look there?

The way that I have it working is:

 set up qb_object
 attach a service to it
 #redirect to the authorize_url
 access that same qb_object
 access service to do the rest. 

It might make sense to separate out the get_service procedure and the get_authorize_url procedure, just to make that distinction clearer.

In Django I'm doing this between views using a global object. It's not ideal.

simonv3 added a commit that referenced this issue Jul 24, 2014
Functionality should be separate for the two, but get_authorize_url sets up a service if there isn't one already

Brought up because of issue #8
@rubinovitz
Copy link
Contributor Author

I'm getting a new error now that I'm using a global object. Maybe I'm doing the process wrong.

  1. make a global QuickBooks object (qb = Quickbooks(credentials))
  2. qb.get_authorize_url()
    3.
# I'm using flask
oauth_verifier = request.args.get('oauth_verifier')
oauth_token = request.args.get('oauth_token')
# these both print fine
print 'oauth token %s' %(oauth_token)
print 'oauth verifier %s' %(oauth_verifier)
qb.set_up_service()
qb.get_access_tokens( oauth_verifier)

Then I get the following error: KeyError: 'Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: oauth_problem=parameter_rejected&oauth_parameters_rejected=oauth_token'

@simonv3
Copy link
Owner

simonv3 commented Jul 29, 2014

It looks like you're setting up a new service on the second to last line. If you already have your oauth token, I think you shouldn't need to do that again. Can you try just calling get_access_tokens() at the end?

@rubinovitz
Copy link
Contributor Author

I set up the new service because when I skip the .set_up_service() step I
get this error:

AttributeError: 'NoneType' object has no attribute 'get_auth_session'

On Tue, Jul 29, 2014 at 4:49 AM, Simon [email protected] wrote:

It looks like you're setting up a new service on the second to last line.
If you already have your oauth token, I think you shouldn't need to do that
again. Can you try just calling get_access_tokens() at the end?


Reply to this email directly or view it on GitHub
#8 (comment)
.

Jennifer Rubinovitz

@simonv3
Copy link
Owner

simonv3 commented Jul 30, 2014

That's weird. get_authorize_url() sets a service token on the qbObject if one doesn't already exist. I can't see what would unset that service and turn it into a NoneType. Is there a way for you to check that the two qb objects are the same - it might be a scope issue, where you have a local qb object that has been changed within one method, but that change hasn't been reflected to the global qb object so available to the method on the other side of the authorized URL?

@rubinovitz
Copy link
Contributor Author

Okay it was an issue with my grantUrl in my javascript once I made the QB object global. Sorry about that. Now I'm just getting a 401 error whenever I make a query.

@KobaKhit
Copy link

I am having the same issue here. I think it would very helpful if somebody could update the readme.md with a working example.

@simonv3
Copy link
Owner

simonv3 commented Aug 13, 2014

Hey @KobaKhit, the readme works fine for a Django application. What's the specific issue you're having a difficulty with - are you getting a 401 Unauthorized as well? What is your set up?

@rubinovitz Are you getting a 401 Unauthorized from Quickbooks? Could you show me some code?

@KobaKhit
Copy link

Hello @simonv3, I am using a simple python script and Python 2.7.8 to query the quickbooks online.
I get exactly the same error as @rubinovitz. My code is the following.

from pythonquickbooks.quickbooks import *

qbObject = QuickBooks(
    consumer_key = my_consumer_key,
    consumer_secret = my_consumer_secret,
    callback_url = "http://myapp.com/myapp",
)

authorize_url = qbObject.get_authorize_url() # will create a service, and further set up the qbObject.
print authorize_url # I access the url and retrieve the verifier and the realm id as specified in the read.me

oauth_token= token provided by get_authorize_url()
oauth_verifier = I paste it from the url after accessing it
realm_id = I paste it from the url after accessing it

session = qbObject.get_access_tokens(oauth_verifier) # here I get the same error rubinovitz got

Basically, once I access the authorization url the resulting url contains a token, a verifier, and a realm id. At this point I just copy paste because I simply want to make the api work. I was trying to follow your work flow, but could not figure out what attach a service to it refers to. Help appreciated. I like your work.

@simonv3
Copy link
Owner

simonv3 commented Aug 13, 2014

Okay, so there does indeed seem to be something wrong.

Are you raising the Exception: Query object is not authorized to make that request. exception?

If that's what you're getting, then I think you've done oAuth right, and you got the right access tokens, etc. I think the problem is with how the sessions is managed.

At the moment I don't have a lot of time to track this down much further, especially if it's a problem with Quickbooks, though I would love it if anyone could look into this more. I'll happily accept pull requests and test them.

Note, you should still be able to query QBs, you'll just have to do it without the helper functions until someone figures that out:

For example, this worked for me:

session = qbObject.get_access_tokens(oauth_verifier)
url = "https://qbo.intuit.com/qbo1/"
url += "resource/employees/v2/%s" % (realm_id)

r = session.request("POST", url, header_auth = True, realm = realm_id, params={"format":"json"})

@rubinovitz
Copy link
Contributor Author

Yes, that exception gets raised. I'll look into session management, I
suppose.

On Wed, Aug 13, 2014 at 11:53 AM, Simon [email protected] wrote:

Okay, so there does indeed seem to be something wrong.

Are you raising the Exception: Query object is not authorized to make
that request. exception?

If that's what you're getting, then I think you've done oAuth right, and
you got the right access tokens, etc. I think the problem is with how the
sessions is managed.

At the moment I don't have a lot of time to track this down much further,
especially if it's a problem with Quickbooks, though I would love it if
anyone could look into this more. I'll happily accept pull requests and
test them.


Reply to this email directly or view it on GitHub
#8 (comment)
.

Jennifer Rubinovitz

@gg2572
Copy link

gg2572 commented Jun 16, 2016

So I had that issue as well. I don't know if you guys still have those problems but here's my solution. So in general, we wouldn't need to use session = get_access_tokens(oauth_verifier) every time; instead, what we really need are just the access_token and access_token_secret, which are contained in the session that you created in the first time. Just save the session using pickle.dump(session, 'session_file_name'). The next time you need the access token, just load the session: session = pickle.load('session_file_name'). There you have access_token = session.access_token, and you can create a new qbObject setting the access_token and secret and, we're done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants