Twitter应用中的'set'对象中没有属性'__getitem__'

Apo*_*osh 1 python twitter

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

File "scratch.py", line 6, in <module>
config['oauth_token'],
TypeError: 'set' object has no attribute '__getitem__'</code>
Run Code Online (Sandbox Code Playgroud)

在第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
Run Code Online (Sandbox Code Playgroud)

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

use*_*ica 7

您的配置字典在其中的某处有一个拼写错误,导致它被创建为一个集合而不是字典.也许你打字,而不是:某个地方.

  • 你是对的,一旦你回答了问题,这个问题似乎相当愚蠢:P (3认同)