首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >当使用tweepy游标时,捕获容量错误的最佳实践是什么?

当使用tweepy游标时,捕获容量错误的最佳实践是什么?
EN

Stack Overflow用户
提问于 2018-01-05 08:01:38
回答 1查看 3.3K关注 0票数 16

我正在使用Python的Tweepy库收集大量用户的信息。我已经初始化API,如下所示

api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)

这里有我的代币。这段代码对等级限制错误有很好的响应,但对于其他一些错误则不起作用。例如,我有时会看到以下异常。

tweepy.error.TweepError:{“消息”:“超过容量”,“代码”:130}

我可以使用try以外来处理这个异常,但是我想知道是否有一种方法可以像处理速率限制异常那样在游标中处理这个异常。我看到了像retry_count这样的参数,但我不确定它们是否适用于这种情况,因为它们似乎是为HTTP错误设计的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-10 03:09:02

我看到了像retry_count这样的参数,但我不确定它们是否适用于这种情况,因为它们似乎是为HTTP错误设计的。

好的,根据医生的说法,一些参数有一个HTTP代码对应,这表明它能工作。(以下为我的答覆)

在整个名单中,你对

超过容量,相当于HTTP 503。Twitter暂时容量过剩

因此,您需要的是在实例化retry_errors时提供一个API参数。这将告诉API哪些HTTP状态代码要重试。举个例子:

retry_count=10, retry_delay=5, retry_errors=set([503])

完整的代码清单:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
+------+--------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Code |                                               Text                                               |                                                                                                                                                                                       Description                                                                                                                                                                                        |
+------+--------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|    3 | Invalid coordinates                                                                              | Corresponds with HTTP 400. The coordinates provided as parameters were not valid for the request.                                                                                                                                                                                                                                                                                        |
|   13 | No location associated with the specified IP address                                             | Corresponds with HTTP 404. It was not possible to derive a location for the IP address provided as a parameter on the geo search request.                                                                                                                                                                                                                                                |
|   17 | No user matches for specified terms                                                              | Corresponds with HTTP 404. It was not possible to find a user profile matching the parameters specified.                                                                                                                                                                                                                                                                                 |
|   32 | Could not authenticate you                                                                       | Corresponds with HTTP 401. There was an issue with the authentication data for the request.                                                                                                                                                                                                                                                                                              |
|   34 | Sorry, that page does not exist                                                                  | Corresponds with HTTP 404. The specified resource was not found.                                                                                                                                                                                                                                                                                                                         |
|   36 | You cannot report yourself for spam.                                                             | Corresponds with HTTP 403. You cannot use your own user ID in a report spam call.                                                                                                                                                                                                                                                                                                        |
|   44 | attachment_url parameter is invalid                                                              | Corresponds with HTTP 400. The URL value provided is not a URL that can be attached to this Tweet.                                                                                                                                                                                                                                                                                       |
|   50 | User not found.                                                                                  | Corresponds with HTTP 404. The user is not found.                                                                                                                                                                                                                                                                                                                                        |
|   63 | User has been suspended.                                                                         | Corresponds with HTTP 403 The user account has been suspended and information cannot be retrieved.                                                                                                                                                                                                                                                                                       |
|   64 | Your account is suspended and is not permitted to access this feature                            | Corresponds with HTTP 403. The access token being used belongs to a suspended user.                                                                                                                                                                                                                                                                                                      |
|   68 | The Twitter REST API v1 is no longer active. Please migrate to API v1.1.                         | Corresponds to a HTTP request to a retired v1-era URL.                                                                                                                                                                                                                                                                                                                                   |
|   87 | Client is not permitted to perform this action.                                                  | Corresponds with HTTP 403. The endpoint called is not a permitted URL.                                                                                                                                                                                                                                                                                                                   |
|   93 | This application is not allowed to access or delete your direct messages                         | Corresponds with HTTP 403. The OAuth token does not provide access to Direct Messages.                                                                                                                                                                                                                                                                                                   |
|   99 | Unable to verify your credentials.                                                               | Corresponds with HTTP 403. The OAuth credentials cannot be validated. Check that the token is still valid.                                                                                                                                                                                                                                                                               |
|  120 | Account update failed: value is too long (maximum is nn characters)                              | Corresponds with HTTP 403. Thrown when one of the values passed to the update_profile.json endpoint exceeds the maximum value currently permitted for that field. The error message will specify the allowable maximum number of nn characters.                                                                                                                                          |
|  130 | Over capacity                                                                                    | Corresponds with HTTP 503. Twitter is temporarily over capacity.                                                                                                                                                                                                                                                                                                                         |
|  131 | Internal error                                                                                   | Corresponds with HTTP 500. An unknown internal error occurred.                                                                                                                                                                                                                                                                                                                           |
|  135 | Could not authenticate you                                                                       | Corresponds with HTTP 401. Timestamp out of bounds (often caused by a clock drift when authenticating - check your system clock)                                                                                                                                                                                                                                                         |
|  144 | No status found with that ID.                                                                    | Corresponds with HTTP 404. The requested Tweet ID is not found (if it existed, it was probably deleted)                                                                                                                                                                                                                                                                                  |
|  150 | You cannot send messages to users who are not following you.                                     | Corresponds with HTTP 403. Sending a Direct Message failed.                                                                                                                                                                                                                                                                                                                              |
|  151 | There was an error sending your message: reason                                                  | Corresponds with HTTP 403. Sending a Direct Message failed. The reason value will provide more information.                                                                                                                                                                                                                                                                              |
|  160 | You've already requested to follow user                                                          | Corresponds with HTTP 403. This was a duplicated follow request and a previous request was not yet acknowleged.                                                                                                                                                                                                                                                                          |
|  161 | You are unable to follow more people at this time                                                | Corresponds with HTTP 403. Thrown when a user cannot follow another user due to some kind of limit                                                                                                                                                                                                                                                                                       |
|  179 | Sorry, you are not authorized to see this status                                                 | Corresponds with HTTP 403. Thrown when a Tweet cannot be viewed by the authenticating user, usually due to the Tweet’s author having protected their Tweets.                                                                                                                                                                                                                             |
|  185 | User is over daily status update limit                                                           | Corresponds with HTTP 403. Thrown when a Tweet cannot be posted due to the user having no allowance remaining to post. Despite the text in the error message indicating that this error is only thrown when a daily limit is reached, this error will be thrown whenever a posting limitation has been reached. Posting allowances have roaming windows of time of unspecified duration. |
|  186 | Tweet needs to be a bit shorter.                                                                 | Corresponds with HTTP 403. The status text is too long.                                                                                                                                                                                                                                                                                                                                  |
|  205 | You are over the limit for spam reports.                                                         | Corresponds with HTTP 403. The account limit for reporting spam has been reached. Try again later.                                                                                                                                                                                                                                                                                       |
|  215 | Bad authentication data                                                                          | Corresponds with HTTP 400. The method requires authentication but it was not presented or was wholly invalid.                                                                                                                                                                                                                                                                            |
|  220 | Your credentials do not allow access to this resource.                                           | Corresponds with HTTP 403. The authentication token in use is restricted and cannot access the requested resource.                                                                                                                                                                                                                                                                       |
|  251 | This endpoint has been retired and should not be used.                                           | Corresponds to a HTTP request to a retired URL.                                                                                                                                                                                                                                                                                                                                          |
|  261 | Application cannot perform write actions.                                                        | Corresponds with HTTP 403. Thrown when the application is restricted from POST, PUT, or DELETE actions. Check the information on your application dashboard. See How to appeal application suspension and other disciplinary actions.                                                                                                                                                    |
|  271 | You can’t mute yourself.                                                                         | Corresponds with HTTP 403. The authenticated user account cannot mute itself.                                                                                                                                                                                                                                                                                                            |
|  272 | You are not muting the specified user.                                                           | Corresponds with HTTP 403. The authenticated user account is not muting the account a call is attempting to unmute.                                                                                                                                                                                                                                                                      |
|  323 | Animated GIFs are not allowed when uploading multiple images.                                    | Corresponds with HTTP 400. Only one animated GIF is allowed to be attached to a single Tweet.                                                                                                                                                                                                                                                                                            |
|  324 | The validation of media ids failed.                                                              | Corresponds with HTTP 400. There was a problem with the media ID submitted with the Tweet.                                                                                                                                                                                                                                                                                               |
|  325 | A media id was not found.                                                                        | Corresponds with HTTP 400. The media ID attached to the Tweet was not found.                                                                                                                                                                                                                                                                                                             |
|  326 | To protect our users from spam and other malicious activity, this account is temporarily locked. | Corresponds with HTTP 403. The user should log in to https://twitter.com to unlock their account before the user token can be used.                                                                                                                                                                                                                                                      |
|  327 | You have already retweeted this Tweet                                                            | Corresponds with HTTP 403. The user cannot retweet the same Tweet more than once.                                                                                                                                                                                                                                                                                                        |
|  354 | The text of your direct message is over the max character limit.                                 | Corresponds with HTTP 403. The message size exceeds the number of characters permitted in a Direct Message.                                                                                                                                                                                                                                                                              |
|  385 | You attempted to reply to a Tweet that is deleted or not visible to you.                         | Corresponds with HTTP 403. A reply can only be sent with reference to an existing public Tweet.                                                                                                                                                                                                                                                                                          |
|  386 | The Tweet exceeds the number of allowed attachment types.                                        | Corresponds with HTTP 403. A Tweet is limited to a single attachment resource (media, Quote Tweet, etc.)                                                                                                                                                                                                                                                                                 |
+------+--------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48117126

复制
相关文章
分享10个必备的VS Code技巧和窍门,提高你的开发效率
你知道全球73%的开发者都依赖于同一个代码编辑器吗?是的,2023年Stack Overflow开发者调查结果已经出来了,而且再次证明,Visual Studio Code是迄今为止使用最广泛的开发环境。
前端达人
2023/09/11
5660
分享10个必备的VS Code技巧和窍门,提高你的开发效率
Visual Studio Code1.67版本已正式发布,新增Rust指南
Visual Studio Code1.67版本已正式发布,该版本包含大量增强生产力的更新项:
小柔
2023/10/14
3670
Visual Studio Code1.67版本已正式发布,新增Rust指南
maven缺少依赖包,强制更新依赖命令
-DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。
一个会写诗的程序员
2020/04/30
7.3K0
【IOC 控制反转】Android 视图依赖注入 ( 视图依赖注入步骤 | 视图依赖注入代码示例 )
Android 依赖注入的核心就是通过反射获取 类 / 方法 / 字段 上的注解 , 以及注解属性 ; 在 Activity 基类中 , 获取该注解 以及 注解属性 , 进行相关操作 ;
韩曙亮
2023/03/29
7060
【IOC 控制反转】Android 视图依赖注入 ( 视图依赖注入步骤 | 视图依赖注入代码示例 )
提高生产力的10个必备VS Code技巧和窍门
快来免费体验ChatGpt plus版本的,我们出的钱 体验地址:https://chat.waixingyun.cn 可以加入网站底部技术群,一起找bug,另外新版作图神器已上线 https://cube.waixingyun.cn/home
前端小智@大迁世界
2023/09/10
3410
提高生产力的10个必备VS Code技巧和窍门
打包并自动安装sql数据库
打包,并自动安装SQL数据库 应一位网友的需求,并修正了MVP李洪根".NET平台下WEB应用程序的部署(安装数据库和自动配置)"中的osql用法错误,已测试通过。 一).创建部署项目 1. 在“文件”菜单上指向“添加项目”,然后选择“新建项目”。 2. 在“添加新项目”对话框中,选择“项目类型”窗格中的“安装和部署项目”,然后选择“模板”窗格中的“安装项目”。在“名称”框中键入 setup1。 3. 单击“确定”关闭对话框。 4. 项目被添加到解决方案资源管理器中,并且文件系统编辑器打开。
阿新
2018/04/09
2.5K0
开发者openshift4使用入门教程 - 9 - 通过IDE插件无缝衔接
我所在的公司目前使用的K8S是RedHat的OpenShift 4, 虽然有官方文档, 并且有专门的 Develop 章节, 但是实际使用发现, 开发者(特别是中国的开发者, 传统行业\金融行业的开发者)关注的功能和章节相去甚远. 所以我专门针对开发经常问我的问题, 总结出来这个系列文章.
东风微鸣
2022/04/21
3.8K0
开发者openshift4使用入门教程 - 9 - 通过IDE插件无缝衔接
使用Visual Studio Code开发.NET Core看这篇就够了
在本文中,我将带着大家一步一步的通过图文的形式来演示如何在Visual Studio Code中进行.NET Core程序的开发,测试以及调试。尽管Visual Studio Code的部分功能还达不到Visual Studio的水平,但它实际上已经足够强大来满足我们的日常开发。而且其轻量化,插件化以及跨平台的特性则是VS所不具备的。而且Visual Studio Code还可以通过社区来创建一系列的扩展来增强其功能,且社区已经足够活跃。我们可以期待更多很酷的扩展和功能来增强VS Code,这将使在这个轻量级,跨平台编辑器中的开发.NET Core应用程序更加流畅和有趣。赶紧跟着博主一起开始今天的文章吧!
依乐祝
2018/11/12
5.7K0
Visual Studio 2017 15.8 版发行说明
显著提升了在运行包含多个测试项目的大型解决方案期间的性能。 在我们的实验室中,超过 10,000 个 MSTest 的解决方案执行单个测试的速度提高了 82%!
Edi Wang
2019/07/08
8.2K0
Visual Studio 2017 15.8 版发行说明
编写通用 Hello World 驱动程序 (KMDF)
本主题介绍了如何使用内核模式驱动程序框架 (KMDF) 编写非常小的通用 Windows 驱动程序。
战神伽罗
2019/07/24
4.2K0
编写通用 Hello World 驱动程序 (KMDF)
Java中抽象类和接口中可以有构造方法吗?
Java中抽象类和接口中可以有构造方法吗? -----------------------------------------------------------------------------
黑泽君
2018/10/11
2K0
VsCode中使用Jupyter
(以前称为IPython Notebook)是一个开源项目,可让您轻松地在一个名为Notebook的画布上组合Markdown文本和可执行的Python源代码。
云深无际
2020/11/03
6.1K0
VsCode中使用Jupyter
Android Studio 3.6 发布啦,快来围观
Android Studio 3.6 稳定版终于来了,此版本的 Android Studio 包括对一些设计工具的更新,包括布局编辑器和资源管理器。
GSYTech
2020/03/20
9K0
Android Studio 3.6 发布啦,快来围观
Asp.Net MVC4入门指南(7):给电影表和模型添加新字段
在本节中,您将使用Entity Framework Code First来实现模型类上的操作。从而使得这些操作和变更,可以应用到数据库中。 默认情况下,就像您在之前的教程中所作的那样,使用 Entity Framework Code First自动创建一个数据库,Code First为数据库所添加的表,将帮助您跟踪数据库是否和从它生成的模型类是同步的。如果他们不是同步的,Entity Framework将抛出一个错误。这非常方便的在开发时就可以发现错误,否则您可能会在运行时才发现这个问题。 (由一个晦涩的错
葡萄城控件
2018/01/10
2K0
Asp.Net MVC4入门指南(7):给电影表和模型添加新字段
Visual Studio 2008 每日提示(三十五)
#351、在类视图里查看类关系图 原文链接:You can view the Class Diagram for a class from the Class View 操作步骤: 在类视图里,有个查看类关系图的图标按钮 单击这个图标,可以添加一个类的关系模型,或者,如果没有建立关系图就会建立它。 也可以通过“类视图上下文菜单.类视图项.查看类关系图”命令来查看类关系图。 评论:这个功能对系统设计非常有用。 #352、在类视图里调用静态方法 原文链接:You can Invoke a Static
Jianbo
2018/03/01
9590
OpenCV ImageWatch插件安装与使用说明
本文介绍了OpenCV Image Watch插件的安装与使用,该插件可以为图像处理任务提供实时反馈,并支持多种图像格式。作者还分享了在Visual Studio中如何使用该插件进行图像处理任务,包括图像查看、图像监视、图像保存等功能。
chaibubble
2018/01/02
2.6K0
OpenCV ImageWatch插件安装与使用说明
sql数据库打包部署安装
目的:在客户端服务器上”附加数据库文件”。 一).创建部署项目 1. 打开VS.NET2005。 2.在“文件”菜单上指向“新建项目”。 3. 在“新建项目”对话框中,选择“项目类型”窗格中的”其他项
阿新
2018/04/09
2.4K0
sql数据库打包部署安装
Visual Studio Code 1.67调整文件嵌套、Markdown导航
Visual Studio Code 1.67发布于5月5日,可以从项目网站下载,适用于Linux、Windows或Mac。新特性中特别关注的是浏览器文件嵌套和Markdown代码导航。该版本还带来了Java扩展的更新。
小柔
2023/10/14
2910
[经验总结] 在 windows 命令窗
在IDE里面直接执行 cpu.py文件是正常的,正常输出 CPU 信息,但放到命令窗口执行却提示 config 模块不存在
py3study
2020/01/20
5850
Win 平台做 Python 开发的最佳组合:MS Terminal 和 VS Code
使用 Windows 系统一大好处是它的应用太丰富了,甚至强大的 GPU 也能在闲暇时间做点其它「工作」。然而与 Linux 或 macOS 不同,在 Windows 上做开发总会遇到很多挑战,不论是文件编码、环境控制还是项目编译,开发过程中总会有一些神奇的收获。
Python猫
2019/09/25
4.5K0
Win 平台做 Python 开发的最佳组合:MS Terminal 和 VS Code

相似问题

代码映射未出现在Visual Studio 2013中

15

JTable未出现在窗口中

10

图形未出现在窗口中

10

未出现在Visual Studio测试资源管理器中的测试

40

报告查看器未出现在工具箱中- Visual Studio 2017

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文