【问题标题】:What does TypeError: 'OAuth2FlowNoRedirectResult' object is not iterable meanTypeError: 'OAuth2FlowNoRedirectResult' object is not iterable 是什么意思
【发布时间】:2017-08-17 00:39:12
【问题描述】:

我正在使用 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)

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

【问题讨论】:

    标签: python-3.x dropbox-api


    【解决方案1】:

    问题似乎出在这一行:

    access_token, user_id = flow.finish(code)
    

    那里的DropboxOAuth2FlowNoRedirect.finish 方法返回一个OAuth2FlowNoRedirectResult 对象。您正在尝试解压缩到一个元组 (access_token, user_id),实际上是在尝试对其进行迭代以执行此操作,但失败了,因为没有其他东西可以迭代。

    DropboxOAuth2FlowNoRedirect 的文档中有一些示例代码展示了如何使用 DropboxOAuth2FlowNoRedirect.finish。

    【讨论】:

      【解决方案2】:

      修改以下代码行如下-

      access_token,user_id= flow.finish(code)
      

      到

      access_token= flow.finish(code)
      

      流程.完成

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

      【讨论】:

        猜你喜欢
        • 2017-08-01
        • 1970-01-01
        • 2022-11-24
        • 2021-06-18
        • 2021-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多