KeyError: 'real_name'
Closed this issue · 7 comments
python exporter.py -o out -c -r
Traceback (most recent call last):
File "exporter.py", line 410, in
data_ch = parse_channel_history(ch_hist, users)
File "exporter.py", line 263, in parse_channel_history
"real_name": name_from_uid(msg["user"], users, True),
File "exporter.py", line 204, in name_from_uid
return user["real_name"] if real else user["name"]
KeyError: 'real_name'
Got the same traceback. Fixed that using the following:
diff --git a/exporter.py b/exporter.py
index a962561..72d2aec 100644
--- a/exporter.py
+++ b/exporter.py
@@ -1,3 +1,4 @@
+import time
import os
import sys
import requests
@@ -201,7 +202,7 @@ def parse_channel_list(channels, users):
def name_from_uid(user_id, users, real=False):
for user in users:
if user["id"] == user_id:
- return user["real_name"] if real else user["name"]
+ return user["profile"]["real_name"] if real else user["name"]
return "[null user]"
@@ -365,6 +366,7 @@ if __name__ == "__main__":
os.makedirs(out_dir, exist_ok=True)
full_filepath = os.path.join(out_dir, filename)
print("Writing output to %s" % full_filepath)
+ time.sleep(10)
with open(full_filepath, mode="w") as f:
if a.json:
json.dump(data, f, indent=4)
Also included a delay to prevent ERROR: 429 Too Many Requests
The KeyError is gone.
But I'm still getting the ERROR: 429 Too Many Requests
.
Even for sleep(600) I get the same error.
Maybe you ran out of quota? I waited to next day
Good catch, @kvdb! According to Slack docs, real_name
should be found in both user
and user["profile"]
, but it looks like sometimes it's missing from the former and not the latter. Should be fixed now.
About rate limits, I'm not sure what your usage history was, but Slack describes their policies here. Also, exporter.py
doesn't currently display this, but I believe a response of HTTP 429 comes with a Retry-After
header telling you the number of seconds until you can try again.
Closing the KeyError
issue for now. Could any rate limiting problems be added as a new issue? Thanks.