Skip to content

Instantly share code, notes, and snippets.

@BlaneyXYZ
Last active March 30, 2021 07:53
Show Gist options
  • Save BlaneyXYZ/98469ddd523c43cd4ded69d679104e4e to your computer and use it in GitHub Desktop.
Save BlaneyXYZ/98469ddd523c43cd4ded69d679104e4e to your computer and use it in GitHub Desktop.
PUT all files in a folder to a REST endpoint
#!/usr/bin/env python3
import os
import requests
from requests.auth import HTTPBasicAuth
directory = os.fsencode(os.getcwd())
for file in os.listdir(directory):
filename = os.fsdecode(file)
response = requests.post('http://localhost', files={'file': open(filename, 'rb')}, auth=HTTPBasicAuth('user', 'pass'))
print(response.content)
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment