Last active
          June 12, 2023 12:15 
        
      - 
      
- 
        Save ErikKalkoken/f3ab28617d5099531ded865d111dbac1 to your computer and use it in GitHub Desktop. 
    Fetch a private file from Slack
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 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) | |
There's a mistake in this code:
You are missing f in L9
{f'Authorization': f'Bearer {slack_token}'})
@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
  
            
If somebody came here from google, you might also be interested in this script: https://github.com/auino/slack-downloader
I have just created a pull request such that it works with the latest Slack API.