Skip to content Skip to sidebar Skip to footer

Python Dropbox Api Error

I'm following the tutorial here So far so good but the upload example give me errors. The code: from dropbox import client, rest, session f = open('txt2.txt') # upload a file resp

Solution 1:

You haven't initialized the client object. Refer to the tutorial again and you'll see this:

client = client.DropboxClient(sess)

The sess object must also be initialized before calling the client module's DropboxClient method:

sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)

You should have all the required parameters (i.e., APP_KEY, APP_SECRET, ACCESS_TYPE) assigned to you when you register your application.

Solution 2:

I followed the edited code of yours and things worked out perfectly.

from dropbox import client, rest, session

# Get your app key and secret from the Dropbox developer website
app_key = 'enter-your-app_key'
app_secret = 'enter-your-app_secret'

ACCESS_TYPE = 'dropbox'

sess = session.DropboxSession(app_key, app_secret, ACCESS_TYPE )

request_token = sess.obtain_request_token()

# Make the user sign in and authorize this token
url = sess.build_authorize_url(request_token)
print"url:", url
print"Please authorize in the browser. After you're done, press enter."
raw_input()

# This will fail if the user didn't visit the above URL and hit 'Allow'
access_token = sess.obtain_access_token(request_token)

client = client.DropboxClient(sess)
print"linked account:", client.account_info()

f = open('/home/anurag/Documents/sayan.odt')
response = client.put_file('/sayan.odt', f)
print"uploaded:", response

Notice the response and file location on your system, in your code that doesn't matches.

Thanks.

Post a Comment for "Python Dropbox Api Error"