- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在收集大量使用 Python 的 Tweepy 库的用户的信息。我已将 API 初始化如下
api = tweepy.API(auth,wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
其中 auth 包含我的 token 。此代码可以很好地响应速率限制错误,但不适用于其他一些错误。例如,我有时会看到以下异常。
tweepy.error.TweepError: [{'message': 'Over capacity', 'code': 130}]
我可以使用 try except 来处理这个异常,但我想知道是否有一种方法可以在游标内处理这个异常,就像我处理速率限制异常一样。我看到像 retry_count 这样的参数,但我不确定它们是否适用于这种情况,因为它们似乎是为 HTTP 错误设计的。
最佳答案
I see parameters like retry_count, but I'm not sure if they will work for this case as they seem designed for HTTP errors.
嗯,according to the docs , 一些参数有一个 HTTP 代码对应,这表明它会起作用。 (整个列表在我的答案下方)
在整个列表中,你感兴趣的是
Over capacity 对应 HTTP 503。Twitter 暂时重载
因此,您需要在实例化 API
时提供一个 retry_errors
参数。这将告诉 API 重试哪些 HTTP 状态代码。一个例子:
retry_count=10, retry_delay=5, retry_errors=set([503])
整个代码列表:
+------+--------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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.) |
+------+--------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
关于python - 使用 tweepy 游标时,捕获容量过大错误的最佳做法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48117126/
多个 ChildException catch block 和一个 Exception catch block 之间哪个更好? 更好,我的意思是以良好的实践方式。 举例说明: public stati
我正在尝试将脱机计算机记录在文本文件中,以便以后可以再次运行它们。似乎没有被记录或捕获。 function Get-ComputerNameChange { [CmdletBinding()]
我正在将 Scala 'try/catch' 测试代码转换为使用 'intercept' 有没有我不应该使用“拦截”的场景?使用 'intercept' 而不是 'try/catch' 的唯一好处是简
我对erlang很陌生,我正在尝试使用基本的try/catch语句来工作。我正在使用Webmachine处理一些请求,我真正想做的就是解析一些JSON数据并将其返回。如果JSON数据无效,我只想返回一
我不知道如何捕获删除按键。我发现在 ASCII 代码表中,它位于 127 位,但是 if (Key = #127) then 却无济于事。 然后我检查了 VK_DELETE 的值,它是 47。尝试使用
我很少在失败时对数据库查询使用唯一的错误消息 我经常使用简短的标准消息,例如“数据库错误/失败。请与网站管理员联系”或类似的消息。或自动发送给我 我正在寻找一种在PDO中全局设置一次try {}和ca
我有一个变量CompletableFuture completableFuture 。我希望能够使用任何类型的对象来完成它。例如:completableFuture.complete(new Stri
我认为这是基本的东西,但我不知道该怎么做。为什么我得到 IOException never throw in body of相应的 try 语句 public static void main(Str
我在此代码中遇到 JSON 异常: JSONObject jObject = new JSONObject(JSONString); pontosUsuario.setIdUsuari
我正在尝试打印出用单引号括起来的文本。 /bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_1' /bin/
我这里遇到了一点问题。我想弄清楚如何捕获 IllegalArgumentException。对于我的程序,如果用户输入负整数,程序应该捕获 IllegalArgumentException 并询问用户
我无法理解 EJBTransactionRolledbackException。 我有实体: @Entity public class MyEntity { @Id @Generate
对于我给自己提出的以下挑战,如果社区的经验给我任何建议,我将不胜感激 - 即,这里有任何关于最佳方法/方向的指示吗? 要求 允许收集/实时监控从用户 Windows PC 到一组特定 IP 地址(或
我想在我的 ABAP 代码中捕获并处理 SAPSQL_DATA_LOSS。 我试过这个: try. SELECT * FROM (rtab_name) AS rtab
我知道捕获错误不是一个好的做法,但在这种情况下,这样做很重要。我正在尝试运行一个包含游戏一部分的 jar,但它给了我一个 unsatisfiedlink 错误,但这是有趣的部分:我正在使用这段代码:
我有一个表单页面,当我保存它时,它会覆盖数据库。表单页面中有一个文本框,允许用户输入 4000 个字符,但如果用户输入的字符超过此值,则会出现以下错误: ERROR 15:54:05 Abstrac
我想知道在python中绑定(bind)键的最简单方法 例如,默认的 python 控制台窗口出现并等待,然后在 psuedo -> if key "Y" is pressed: print (
下面是别人写的类。 我面临的问题是,当它进入parse method时与 null as the rawString ,它正在扔NumberFormatException 。 所以我想做的是,我应该捕
我有一个简单的脚本,可以捕获所有鼠标单击,除非您单击实际有效的内容。链接、Flash 视频等。我如何调整它,以便无论用户点击什么,在视频加载、新页面加载等之前,它都会发送我构建的简单 GET 请求?
我有一个带有一些选择列表的表单,当选择某些值时,这些列表将显示/隐藏更多输入字段。 问题是大多数用户都是数据输入人员,因此他们在输入数据时大量使用键盘,并且选择列表的 change 事件仅在焦点离开输
我是一名优秀的程序员,十分优秀!