python - Twitter 应用程序中的 '__getitem__' 对象中没有属性 'set'

标签 python twitter

我正在构建一个简单的应用程序,它只为用户流式传输 Twitter 流,并不断出现错误

File "scratch.py", line 6, in <module>
config['oauth_token'],
TypeError: 'set' object has no attribute '__getitem__'</code>

第 6 行。

源代码是:

from twitter import TwitterStream

config = { --- add your 4 horsemen in this dictionary --- }
ts = TwitterStream(
                    auth=OAuth(
                        config['oauth_token'],
                        config['oauth_token_secret'],
                        config['key'],
                        config['secret']
                        )
                    )
openstream = ts.statuses.filter(track=words)
for item in openstream:
    print item['user']['screen_name'], datetime.strptime(item['created_at'],'%a %b %d %H:%M:%S +0000 %Y'), item['text']
    if datetime.now() &gt; stop:
        print datetime.now().isoformat()
        break

“oauth-token”和其他变量的值当然是特定于应用程序的,我不能在这里透露它们。我是一个 python 新手,不能真正理解这里的错误,很高兴得到任何帮助。

最佳答案

您的配置字典中某处有一个拼写错误,导致它被创建为一个集合,而不是一个字典。也许您在某处键入了 , 而不是 :

关于python - Twitter 应用程序中的 '__getitem__' 对象中没有属性 'set',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946607/

相关文章:

python - 如何旋转 python turtle 对象

c++ - 使用 CUDA 实现、python (pycuda) 或 C++ 处理图像?

ios - index 0 beyond bounds for empty array - 找到数组但如何修复?

Twitter 分享 - 将 urlencode 参数 %2C 重定向到 %252C

python - 使用 wget 下载指定大小的 Twitter 图片

python - 没有密码验证的Sendmail (Python 2.4)

python - 将 python 模块从现有环境移动到 anaconda

Android Intent startActivityForResult 未正确返回

java - "No authentication challenges found"与 twitter4j

Python JSON/Dict 搜索和值更新