什么是TypeError:' OAuth2FlowNoRedirectResult'对象不是可迭代的意思

时间:2017-08-17 00:39:12

标签: python-3.x dropbox-api

我正在使用dropbox python扩展,我收到此错误消息:

TypeError: 'OAuth2FlowNoRedirectResult' object is not iterable

到目前为止这是代码:

import dropbox
flow = dropbox.DropboxOAuth2FlowNoRedirect(app_key, app_secret)

# Have the user sign in and authorize this token
authorize_url = flow.start()
print ('1. Go to: ' + authorize_url)
print ('2. Click "Allow" (you might have to log in first)')
print ('3. Copy the authorization code.')
code = input("Enter the authorization code here: ").strip()

# This will fail if the user enters an invalid authorization code
access_token, user_id = flow.finish(code)

f = open('Top Secret.jpg', 'rb')
response = client.put_file('Top Secret.jpg', f)
print ("uploaded:", response)
f.close()

f, metadata = client.get_file_and_metadata('/Top Secret.jpg')
out = open('Test.jpg', 'wb')
out.write(f.read())
out.close()
print (metadata)

我出于显而易见的原因排除了应用密钥和应用密钥。

2 个答案:

答案 0 :(得分:0)

问题似乎在这一行:

access_token, user_id

DropboxOAuth2FlowNoRedirect.finish方法返回一个OAuth2FlowNoRedirectResult对象。您尝试解压缩到元组(=LOWER( CONCATENATE( DEC2HEX(RANDBETWEEN(0,POWER(16,8)),8), "-", DEC2HEX(RANDBETWEEN(0,POWER(16,4)),4),"-","4", DEC2HEX(RANDBETWEEN(0,POWER(16,3)),3),"-", DEC2HEX(RANDBETWEEN(8,11)), DEC2HEX(RANDBETWEEN(0,POWER(16,3)),3),"-", DEC2HEX(RANDBETWEEN(0,POWER(16,8)),8), DEC2HEX(RANDBETWEEN(0,POWER(16,4)),4) ) ) ),有效地尝试迭代它来执行此操作,这会失败,因为没有其他任何东西可以迭代。

有一些示例代码显示如何在DropboxOAuth2FlowNoRedirect.finish的文档中使用DropboxOAuth2FlowNoRedirect

答案 1 :(得分:0)

修改以下代码行,如下所示 -

access_token,user_id= flow.finish(code)

access_token= flow.finish(code)

  

flow.finish

方法不返回元组。它返回一个对象。