【问题标题】:Errno 10054: An existing connection was forcibly closed by the remote host - Tweepy ErrorErrno 10054:现有连接被远程主机强行关闭 - Tweepy 错误
【发布时间】:2022-03-19 00:26:46
【问题描述】:

我正在尝试从拥有近 60 万关注者的 Twitter 帐户中检索关注者信息。我能够使用此代码在另一个帐户上检索大约 280,000 名关注者,没有任何问题。但是对于更大的帐户,我会收到此错误:

[Errno 10054] 现有连接被远程主机强行关闭

我确定我没有两个打开的连接。我正在使用等待限制参数。

  1. 你知道我需要做什么才能获得全部 60 万左右的关注者吗?

  2. 有没有办法编辑代码,以便在出现该错误时将检索到的关注者写入 CSV?或者我可以将检索到的数据写入每个循环的 CSV。现在,一旦代码出错,我就会丢失它检索到的所有内容,而且我知道它会在出错之前检索到数十万粉丝。如果我能保留这些数据会很有帮助。

我正在使用的代码是从 [Retrieve Twitter Followers - Brianna Herold][1] 中检索到的:

import pandas as pd

# Twitter API credentials
consumer_key = '***'
consumer_secret = '***'
access_token = '***'
access_secret = '***'

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

screen_name = '***'
ids = []
for fid in Cursor(api.followers_ids, screen_name=screen_name, count=5000).items():
    ids.append(fid)

info = []
for i in range(0, len(ids), 100):
    try:
        chunk = ids[i:i+100]
        info.extend(api.lookup_users(user_ids=chunk))
    except:
        import traceback
        traceback.print_exc()
        print('Something went wrong, skipping...')

data = [x._json for x in info]
df = pd.DataFrame(data)
df = df[['id', 'name', 'screen_name', 'location', 'description', 'url', 'followers_count', 'friends_count', 'created_at', 'verified']]
df.to_csv(r' myfilepath)


  [1]: https://towardsdatascience.com/how-to-download-twitter-friends-or-followers-for-free-b9d5ac23812

【问题讨论】:

  • 你找到解决办法了吗?还是什么原因造成的?

标签: tweepy twitterapi-python


【解决方案1】:

我遇到了同样的问题。

Twitter 似乎限制了他们的 TLS 1.2 密码套件。现在唯一可用的是:

TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f) ECDH x25519 (eq. 3072 bits RSA) FS128TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030) ECDH x25519 (eq. 3072 bits RSA) FS256TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca8) ECDH x25519 (eq. 3072 bits RSA) FS

这意味着运行应用程序的服务器需要这些可用并安装在其上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-18
    • 2012-02-07
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多