2014-01-06 88 views
1

我建立一个简单的应用程序,只是流Twitter的数据流的用户,“设置”对象没有属性“__getitem__”和不断收到错误在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的标记”等变量的值当然是特定应用的,我不能说出来呢。我是一个Python新手,不能真正理解这里的错误,并会很高兴有任何帮助。

回答

7

你的配置字典有一个错误的地方,导致它被创建为一个集合,而不是一个字典。也许你在某处输入了,而不是:

+3

你说得对,这个问题似乎很愚蠢,一旦你回答了:P –