python - 绕过 IncompleteRead 异常

标签 python tweepy urllib3

我正在使用 Tweepy 在 Python3 中编写一个 Twitter 流监听器。流式传输一段时间后出现此错误:

urllib3.exceptions.ProtocolError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))

我怎样才能绕过它,重新连接并继续前进?

我做了:

from requests.packages.urllib3.exceptions import ReadTimeoutError, IncompleteRead

和:

while True:
    try:
        twitter_stream.filter(track=keywordlist, follow=userlist)

    except IncompleteRead:
        continue

但还是报错。

最佳答案

您遇到的异常是 urllib3.exceptions.ProtocolError 异常。

尝试:

from urllib3.exceptions import ProtocolError

while True:
    try:
        twitter_stream.filter(track=keywordlist, follow=userlist)

    except ProtocolError:
        continue

关于python - 绕过 IncompleteRead 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44378849/

相关文章:

python - 无法导入 tweepy(Python 3.7 - tweepy 3.5)

python - tweepy 上未指定目标用户错误

python - 使用 urllib3 和 python 2.7 从 url 下载 .txt 文件?

python - 从视频错误中提取帧

python - 在 python setup.py install 期间设置包范围的变量

python - 通过两级索引系列填充 NA 值

tweepy - 如何使用 Anacondas 和 easy_install 安装 Tweepy

python - 如何在 HTTPConnectionPool urllib3 中进行几次重定向后获取响应历史记录

python - 运行 Rasa Stack 时超出最大重试次数并出现连接拒绝错误

python - 如何使用 Tensorflow 模型进行预测?