蟒蛇的Dropbox API错误 [英] python dropbox api error
问题描述
我在下面的教程这里
到目前为止好,但上传的例子给我的错误。在code:
从Dropbox的客户端导入,休息,会话F =开放('txt2.txt')#上传文件
响应= client.put_file('/马格南-opus.txt',F)
打印上载:响应
错误:
回溯(最后最近一次调用):
文件dropbox_ul.py,4号线,上述<&模块GT;
响应= client.put_file('/马格南-opus.txt',F)
AttributeError的:'模块'对象有没有属性'put_file
在哪里我会错呢?
编辑:新的code我正在努力。这实际上是从Dropbox的开发者网站。正如我先前所说,我没有经过认证和设置:
#包括Dropbox的SDK库
从Dropbox的客户端导入,休息,会话#获取从Dropbox的开发者网站您的应用程序键和秘密
APP_KEY ='iqxjea6s7ctxv9j
APP_SECRET ='npac0nca3p3ct9f#ACCESS_TYPE应该是投寄箱或app_folder作为配置为您的应用程序
ACCESS_TYPE ='保管箱'SESS = session.DropboxSession(APP_KEY,APP_SECRET,ACCESS_TYPE)request_token = sess.obtain_request_token()#使在用户登录并授权该令牌
URL = sess.build_authorize_url(request_token)
打印URL,网址
打印请准许在浏览器中。大功告成后,preSS进入。
的raw_input()#如果用户没有访问上述网址,这将失败,并点击允许
的access_token = sess.obtain_access_token(request_token)客户端= client.DropboxClient(SESS)
打印链接帐户,client.account_info()F =开放('txt2.txt')
响应= client.put_file('/马格南-opus.txt',F)
打印上载:响应folder_metadata = client.metadata('/')
打印元数据,folder_metadata楼元= client.get_file_and_metadata('/马格南-opus.txt',REV ='362e2029684fe')
OUT =开放('膨大-opus.txt','W')
out.write(F)
打印(元数据)
和错误:
网址:https://www.dropbox.com/1/oauth/authorize?oauth_token=jqbasca63c0a84m
请在浏览器授权。大功告成之后,preSS进入。 链接帐户:{'referral_link':'https://www.dropbox.com/referrals/NTMxMzM4NjY5','DISPLAY_NAME':'格雷格洛林奇','UID':3133866,'国家':'GB','quota_info :{共享:78211,'配额':28185722880,正常:468671581},电子邮件:alkopop79@gmail.com'}
回溯(最近通话最后一个):
文件dropb.py28行,上述<&模块GT;
响应= client.put_file('/马格南-opus.txt',F)
文件\"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-1.4-py2.7.egg/dropbox/client.py\",线149,在put_file
返回RESTClient.PUT(URL,file_obj头)
文件\"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py\",线146,在PUT
返回cls.request(PUT,网址,身体=人体,头=头,raw_response = raw_response)
文件\"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py\",线113,在请求
提高ErrorResponse(R)
dropbox.rest.ErrorResponse:[403]提供的令牌不允许此操作
您还没有初始化客户端对象。再次参见教程,你会看到这一点:
客户端= client.DropboxClient(SESS)
该SESS对象必须还呼吁在客户端模块的DropboxClient方法之前进行初始化:
SESS = session.DropboxSession(APP_KEY,APP_SECRET,ACCESS_TYPE)
您应该拥有所有分配给您所需要的参数(即APP_KEY,APP_SECRET,ACCESS_TYPE)当您注册您的应用程序。
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
response = client.put_file('/magnum-opus.txt', f)
print "uploaded:", response
The error:
Traceback (most recent call last):
File "dropbox_ul.py", line 4, in <module>
response = client.put_file('/magnum-opus.txt', f)
AttributeError: 'module' object has no attribute 'put_file'
Where did I go wrong?
EDIT: The new code I'm trying. This is actually from the dropbox developer website. As I stated earlier, I did go through the authentication and setup:
# Include the Dropbox SDK libraries
from dropbox import client, rest, session
# Get your app key and secret from the Dropbox developer website
APP_KEY = 'iqxjea6s7ctxv9j'
APP_SECRET = 'npac0nca3p3ct9f'
# ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
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('txt2.txt')
response = client.put_file('/magnum-opus.txt', f)
print "uploaded:", response
folder_metadata = client.metadata('/')
print "metadata:", folder_metadata
f, metadata = client.get_file_and_metadata('/magnum-opus.txt',rev='362e2029684fe')
out = open('magnum-opus.txt', 'w')
out.write(f)
print(metadata)
and the error:
url: https://www.dropbox.com/1/oauth/authorize?oauth_token=jqbasca63c0a84m
Please authorize in the browser. After you're done, press enter.
linked account: {'referral_link': 'https://www.dropbox.com/referrals/NTMxMzM4NjY5', 'display_name': 'Greg Lorincz', 'uid': 3133866, 'country': 'GB', 'quota_info': {'shared': 78211, 'quota': 28185722880, 'normal': 468671581}, 'email': 'alkopop79@gmail.com'}
Traceback (most recent call last):
File "dropb.py", line 28, in <module>
response = client.put_file('/magnum-opus.txt', f)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-1.4-py2.7.egg/dropbox/client.py", line 149, in put_file
return RESTClient.PUT(url, file_obj, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py", line 146, in PUT
return cls.request("PUT", url, body=body, headers=headers, raw_response=raw_response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py", line 113, in request
raise ErrorResponse(r)
dropbox.rest.ErrorResponse: [403] 'The provided token does not allow this operation'
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.
这篇关于蟒蛇的Dropbox API错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!