NameError: global name 'qbObject' is not defined

405 views Asked by At

I'm on FLASK and integrating QUickbook Oauth using QUICKBOOK INTUIT WITH PYTHON

def QBConfig():
    qbObject = QuickBooks(
        consumer_key='qyprdgW*********1vZ5yEnwgNQsO',
        consumer_secret='csnHfPP***WDnA*********CIjzfb3MAb4GI',
        callback_url='http://0.0.0.0:10080/QBGetAccesstoken',
    )
    return qbObject


@app.route('/intuitOauth')
def intuitOauth():

    qbObject = QBConfig()
    authorize_url = qbObject.get_authorize_url()
    # will create a service, and further set up the qbObject.
    return redirect(authorize_url)


@app.route('/QBGetAccesstoken')
def QBGetAccesstoken():
    oauth_verifier = request.args.get('oauth_verifier')
    session = qbObject.get_access_tokens(oauth_verifier)

Here intuitauth function initialize qbObject which is object containing the third party app key configuration.

Quesion is : how could I access qbObject globally?

When intuitauth gets success, callback url called (QBGetAccesstoken). And here is the section where i'm getting error "qbobject is not defined.

The functions are not written in class. qbobject objects might be destroy when callback function called, Can anyone guess the exact issue or solution, how to pass the original object when callback function is called ( page is refresh when callback is calling).

I even tried to store object in session usking like session['qbobj'] = qbObject but unfortunately not worked.

I also tried to reinitialize the object in QBGetAccesstoken function like qbObject = QBConfig(), returns the "None" error with "AttributeError: 'NoneType' object has no attribute".

1

There are 1 answers

0
Mitul Shah On BEST ANSWER

A silly mistake I do to define variable globally. It works fine for below code.

qbObject = QuickBooks(
        consumer_key='qyprdgW*********1vZ5yEnwgNQsO',
        consumer_secret='csnHfPP***WDnA*********CIjzfb3MAb4GI',
        callback_url='http://0.0.0.0:10080/QBGetAccesstoken',
)



@app.route('/intuitOauth')
def intuitOauth():

    authorize_url = qbObject.get_authorize_url()
    # will create a service, and further set up the qbObject.
    return redirect(authorize_url)


@app.route('/QBGetAccesstoken')
def QBGetAccesstoken():
    oauth_verifier = request.args.get('oauth_verifier')
    session = qbObject.get_access_tokens(oauth_verifier)

During the defination, remove the qbObject from function