slack-history-export icon indicating copy to clipboard operation
slack-history-export copied to clipboard

Slack Throttling - Need Help

Open Benoit99 opened this issue 7 years ago • 3 comments

Hi there, When I go to run this, I run into throttling issues from Slack. It starts getting the channel history and then part way through the list of channels it errors out with "requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://slack.com/api/channels.history?channel=C24KKPRT6&latest=1485907199&oldest=1483228800&count=300&inclusive=0&unreads=0&token=.... Looks like I'm exceeding what slack will let me pull down at once. Is there anyway to work around this? Like to avoiding archived channels, avoid messages from bots, run the request in small batches with built in pauses, something else? Thanks!

Benoit99 avatar Jul 26 '17 21:07 Benoit99

same problem here 🤕

in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://slack.com/api/channels.history?channel

shaneholloman avatar May 24 '18 06:05 shaneholloman

diff --git a/slack_history.py b/slack_history.py
index e613aa6..73367c4 100644
--- a/slack_history.py
+++ b/slack_history.py
@@ -21,9 +21,11 @@
 # SOFTWARE.

 from slacker import Slacker
+from time import sleep
 import json
 import argparse
 import os
+import requests

 # This script finds all channels, private channels and direct messages
 # that your user participates in, downloads the complete history for
@@ -66,12 +68,16 @@ def getHistory(pageableObject, channelId, pageSize = 100):
   lastTimestamp = None

   while(True):
-    response = pageableObject.history(
-      channel = channelId,
-      latest  = lastTimestamp,
-      oldest  = 0,
-      count   = pageSize
-    ).body
+    try:
+      response = pageableObject.history(
+        channel = channelId,
+        latest  = lastTimestamp,
+        oldest  = 0,
+        count   = pageSize
+      ).body
+    except requests.exceptions.HTTPError:
+      sleep(30)
+      continue

     messages.extend(response['messages'])

works for me

zavorka avatar Jan 04 '19 12:01 zavorka

It still didn't work for me, so I added sleep(1) before response = pageableObject.history(, and now it does :smile:

pandark avatar Apr 24 '20 15:04 pandark