I am trying to create a class in python that reads the access key / secret for dropbox and then uploads the file. The key / secret part works fine, but I seem to have a problem with recognizing the client object, possibly due to a problem with vs local global variables. I can not find the answer anywhere.
Here is part of my code:
from dropbox import client, rest, session class GetFile(object): def __init__(self, file1): self.auth_user() def auth_user(self): APP_KEY = 'xxxxxxxxxxxxxx' APP_SECRET = 'xxxxxxxxxxxxxx' ACCESS_TYPE = 'dropbox' TOKENS = 'dropbox_token.txt' token_file = open(TOKENS) token_key,token_secret = token_file.read().split('|') token_file.close() sess = session.DropboxSession(APP_KEY,APP_SECRET, ACCESS_TYPE) sess.set_token(token_key,token_secret) client = client.DropboxClient(sess) base, ext = file1.split('.') f, metadata = client.get_file_and_metadata(file1) out = open('/%s_COPY.%s' %(base, ext), 'w') out.write(f.read())
And here is the error:
Traceback (most recent call last): File "access_db.py", line 30, in <module> start = GetFile(file_name) File "access_db.py", line 6, in __init__ self.auth_user() File "access_db.py", line 20, in auth_user client = client.DropboxClient(sess) UnboundLocalError: local variable 'client' referenced before assignment
I am new to python, so let me know if there are other obvious things that I may be doing wrong.
source share