我有以下代码,它在Twitter上获取用户朋友的ID列表。然后将这些ID传递给新创建的列表,但我收到以下错误:
Traceback (most recent call last):
File "twitter.py", line 34, in <module>
twitter.create_list_members(list_id=list_id, user_id=i)
File "/home/graingerkid/.local/lib/python2.7/site-packages/twython/endpoints.py", line 768, in create_list_members
return self.post('lists/members/create_all', params=params)
File "/home/graingerkid/.local/lib/python2.7/site-packages/twython/api.py", line 268, in post
return self.request(endpoint, 'POST', params=params, version=version)
File "/home/graingerkid/.local/lib/python2.7/site-packages/twython/api.py", line 258, in request
api_call=url)
File "/home/graingerkid/.local/lib/python2.7/site-packages/twython/api.py", line 194, in _request
retry_after=response.headers.get('X-Rate-Limit-Reset'))
twython.exceptions.TwythonError: Twitter API returned a 404 (Not Found), Sorry, that page does not exist.
我正在使用版本twython-3.4.0
我的代码是:
# create list and return list id
list_id = twitter.create_list(name=user)['id']
print list_id
# get users following ids
following_ids = twitter.get_friends_ids(screen_name=user)['ids']
print following_ids
for i in chunks(following_ids, 100):
# add memebers to list - 100 at a time
twitter.create_list_members(list_id=list_id, user_id=i)
我做错了什么?
答案 0 :(得分:1)
创建列表后添加一秒钟的睡眠。该页面不存在,因为列表尚未完成创建。
# create list and return list id
list_id = twitter.create_list(name=user)['id']
print list_id
time.sleep(1) # Sleep one second
# get users following ids
following_ids = twitter.get_friends_ids(screen_name=user)['ids']
print following_ids
for i in chunks(following_ids, 100):
# add memebers to list - 100 at a time
twitter.create_list_members(list_id=list_id, user_id=i)