Tweepy 错误 - Python -
Tweepy Error - Python -
我安装了 Tweepy 和 Python-Twitter 并尝试基本代码
import twitter
api = twitter.Api(consumer_key=["X"],
consumer_secret=["X"],
access_token_key=["35X-X"],
access_token_secret=["X"])
print(api.VerifyCredentials())
我尝试 运行:
Traceback (most recent call last):
File "tweepy.py", line 1, in <module>
import twitter
File "/home/rodney/twitter.py", line 1, in <module>
import tweepy
File "/home/rodney/tweepy.py", line 2, in <module>
api = twitter.Api(consumer_key=["X"],
AttributeError: module 'twitter' has no attribute 'Api'
得到这个错误我做了什么:
如果尝试代码:
import twitter
import tweepy
api = twitter.Api(consumer_key=["X"],
consumer_secret=["X"],
access_token_key=["35X-X"],
access_token_secret=["X"])
print(api.VerifyCredentials())
错误:
Traceback (most recent call last):
File "tweepy.py", line 1, in <module>
import tweepy
File "/home/rodney/tweepy.py", line 2, in <module>
import twitter
File "/home/rodney/twitter.py", line 10, in <module>
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
AttributeError: module 'tweepy' has no attribute 'OAuthHandler'
试试这个
你在这里要做的是使用 tweepy 的代码
import tweepy
auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
auth.set_access_token(key, secret)
resp= tweepy.API(auth)
不管你想做什么,剩下的就在你身上。为此,您将需要游标,可以在此处找到 http://docs.tweepy.org/en/v3.5.0/cursor_tutorial.html
pip install python-twitter
在 python3 和 python2
上工作正常
Tweepy 需要两个步骤来设置授权,详见 documentation:
import tweepy
consumer_key = 'XX'
consumer_secret = 'XXX'
access_token = 'XXXX'
access_token_secret = 'XXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print api.verify_credentials()
Tweepy 也不同于 python-twitter - 您可能不需要两者。我也会避免调用您的文件 tweepy.py
,因为这可能会导致以后的导入混乱。
如果正在 pycharm IDE 尝试从文件添加 tweepy 库 --> 设置
Link:https://www.youtube.com/watch?v=pKzfNBTRx5U
我安装了 Tweepy 和 Python-Twitter 并尝试基本代码
import twitter
api = twitter.Api(consumer_key=["X"],
consumer_secret=["X"],
access_token_key=["35X-X"],
access_token_secret=["X"])
print(api.VerifyCredentials())
我尝试 运行:
Traceback (most recent call last):
File "tweepy.py", line 1, in <module>
import twitter
File "/home/rodney/twitter.py", line 1, in <module>
import tweepy
File "/home/rodney/tweepy.py", line 2, in <module>
api = twitter.Api(consumer_key=["X"],
AttributeError: module 'twitter' has no attribute 'Api'
得到这个错误我做了什么:
如果尝试代码:
import twitter
import tweepy
api = twitter.Api(consumer_key=["X"],
consumer_secret=["X"],
access_token_key=["35X-X"],
access_token_secret=["X"])
print(api.VerifyCredentials())
错误:
Traceback (most recent call last):
File "tweepy.py", line 1, in <module>
import tweepy
File "/home/rodney/tweepy.py", line 2, in <module>
import twitter
File "/home/rodney/twitter.py", line 10, in <module>
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
AttributeError: module 'tweepy' has no attribute 'OAuthHandler'
试试这个
你在这里要做的是使用 tweepy 的代码
import tweepy
auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
auth.set_access_token(key, secret)
resp= tweepy.API(auth)
不管你想做什么,剩下的就在你身上。为此,您将需要游标,可以在此处找到 http://docs.tweepy.org/en/v3.5.0/cursor_tutorial.html
pip install python-twitter
在 python3 和 python2
上工作正常Tweepy 需要两个步骤来设置授权,详见 documentation:
import tweepy
consumer_key = 'XX'
consumer_secret = 'XXX'
access_token = 'XXXX'
access_token_secret = 'XXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print api.verify_credentials()
Tweepy 也不同于 python-twitter - 您可能不需要两者。我也会避免调用您的文件 tweepy.py
,因为这可能会导致以后的导入混乱。
如果正在 pycharm IDE 尝试从文件添加 tweepy 库 --> 设置 Link:https://www.youtube.com/watch?v=pKzfNBTRx5U