python dropbox api error

跟風遠走 提交于 2019-12-02 09:11:36

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!