Python Tweepy属性错误
我是python和tweepy新手,收到一条我无法真正理解的错误消息:Python Tweepy属性错误,python,tweepy,Python,Tweepy,我是python和tweepy新手,收到一条我无法真正理解的错误消息: import json from tweepy import Cursor from twitter_client import get_twitter_client if __name__ == '__main__': client = get_twitter_client() with open('home_timeline.jsonl', 'w') as f: for page in
import json
from tweepy import Cursor
from twitter_client import get_twitter_client
if __name__ == '__main__':
client = get_twitter_client()
with open('home_timeline.jsonl', 'w') as f:
for page in Cursor(client.home_timeline, count=200).pages(4):
for status in page:
f.write(json.dumps(status._json)+"\n")
运行此代码会显示以下错误消息:
Traceback (most recent call last):
File "twitter_get_user_timeline.py", line 10, in <module>
for page in Cursor(client.home_timeline, count=200).pages(4):
File "/home/projects/webscraping/testEnv/lib/python3.5/site-packages/tweepy/cursor.py", line 49, in __next__
return self.next()
File "/home/projects/webscraping/testEnv/lib/python3.5/site-packages/tweepy/cursor.py", line 108, in next
data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs)
File "/home/projects/webscraping/testEnv/lib/python3.5/site-packages/tweepy/binder.py", line 239, in _call
return method.execute()
File "/home/projects/webscraping/testEnv/lib/python3.5/site-packages/tweepy/binder.py", line 174, in execute
auth = self.api.auth.apply_auth()
AttributeError: 'function' object has no attribute 'apply_auth'
谢谢你的建议 在第二个文件中,函数
get\u twitter\u client
,行auth=get\u twitter\u auth
您正在auth
中保存get\u twitter\u auth
函数,而不是返回值
用
auth=get\u twitter\u auth()
我无法提高投票率我在这里的声誉太低了,我只能在我自己的问题提出15分钟后接受答案-但不用担心,我会验证它,然后在这里尽快提高投票率:)不,这真的不重要,唯一的目标是帮助,你来这里只是为了欺负我的同事
import os
import sys
from tweepy import API
from tweepy import OAuthHandler
def get_twitter_auth():
"""Setup Twitter authentication.
Return: tweepy.OAuthHandler object
"""
try:
consumer_key = os.environ['TWITTER_CONSUMER_KEY']
consumer_secret = os.environ['TWITTER_CONSUMER_SECRET']
access_token = os.environ['TWITTER_ACCESS_TOKEN']
access_secret = os.environ['TWITTER_ACESS_SECRET']
except KeyError:
sys.stderr.write("TWITER_* environment variables not set\n")
sys.exit(1)
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
return auth
def get_twitter_client():
"""Setup Twitter API client
Return: tweepy.API object
"""
auth = get_twitter_auth
client = API(auth)
return client