I am trying to create a class in python which reads the access key/secret for dropbox and then downloads a file. The key/secret part is working alright, but I seem to be having a problem recognizing the client object, probably due to an issue with global vs local variables. I can't find my answer anywhere else.
Here's 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's 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'm new-ish to python so let me know if there are other obvious things I may be doing wrong.