Skip to content

Instantly share code, notes, and snippets.

@ErikKalkoken
Last active June 12, 2023 12:15
Show Gist options
  • Save ErikKalkoken/f3ab28617d5099531ded865d111dbac1 to your computer and use it in GitHub Desktop.
Save ErikKalkoken/f3ab28617d5099531ded865d111dbac1 to your computer and use it in GitHub Desktop.
Fetch a private file from Slack
# fetching a private Slack file with requests
import requests
import os
slack_token = os.environ['SLACK_TOKEN']
url = 'https://files.slack.com/files-pri/T12345678-F12345678/my_file.jpg'
res = requests.get(url, headers={'Authorization': f'Bearer {slack_token}'})
res.raise_for_status()
with open('my_file.jpg', 'wb') as f:
f.write(res.content)
@reverie-ss
Copy link

There's a mistake in this code:
You are missing f in L9
{f'Authorization': f'Bearer {slack_token}'})

@ErikKalkoken
Copy link
Author

@reverie-ss thanks for heads up. the f was actually in the wrong place. Corrected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment