TypeError: 'Status' object is not iterable

混江龙づ霸主 提交于 2019-12-12 05:48:28

问题


Running this gives me the error TypeError: 'Status' object is not iterable

I'm trying to get the statuses from the user.

import simplejson
import httplib2
import tweepy
import random
import time
import itertools

def paginate(iterable, page_size):
    while True:
        i1, i2 = itertools.tee(iterable)
        iterable, page = (itertools.islice(i1, page_size, None),
                list(itertools.islice(i2, page_size)))
        if len(page) == 0:
            break
        yield page

auth = tweepy.OAuthHandler("removed", "removed")
auth.set_access_token("removed", "removed")

api = tweepy.API(auth)

timeline = api.user_timeline("removed")

for res in paginate(timeline, 50):
    for twet in res[1]:
        print(twet.id)

回答1:


Looks like a pretty simple fix: Just remove the [1] part, and you should get the ID for each tweet.

for res in paginate(timeline, 50):
    for twet in res:
        print(twet.id)


来源:https://stackoverflow.com/questions/26954107/typeerror-status-object-is-not-iterable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!