slack-history-export
slack-history-export copied to clipboard
Slack Throttling - Need Help
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!
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
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
It still didn't work for me, so I added sleep(1)
before response = pageableObject.history(
, and now it does :smile: