提问人:Paul Corcoran 提问时间:5/4/2022 更新时间:5/4/2022 访问量:53
Tweepy 连接错误:主机已强制删除连接
Tweepy connection error: host has forcbily removed the connection
问:
# OAuth2.0 Version
import tweepy as tw
import time
import pandas as pd
#Put your Bearer Token in the parenthesis below
client = tw.Client(bearer_token='removedfromcode',
wait_on_rate_limit=True)
# -is:retweet means I don't want retweets
# lang:en is asking for the tweets to be in english
query = 'Manchester United Man United Man Utd lang:en -is:retweet'
ManUtd_tweets = []
ManUtd_tweets_ids = []
while True:
try:
for tweet in tw.Paginator(client.search_all_tweets, query=query,
user_fields = ['username','public_metrics','description', 'location'],
tweet_fields=['text', 'created_at','public_metrics'],
start_time = '2021-01-01T00:00:00Z',
end_time = '2022-01-01T00:00:00Z', max_results=100) \
.flatten(limit=1000000):
ManUtd_tweets.append(tweet)
ManUtd_tweets_ids.append(tweet['id'])
df = pd.DataFrame(ManUtd_tweets)
except BaseException as error:
time.sleep(60)
print('Error', str(error))
break
df
上面的代码在一段时间后超时,我收到连接错误 10054 - 远程主机强制关闭了现有连接。
关于如何为 Tweepy 解决这个问题的任何想法?
答: 暂无答案
评论