I'd like to upload files to a server using python. That means in this case that when I write http://example.com/files/ in my browser I'd like to see de.txt there in the list of files. How should I change this script to be working? When I run it, python shell writes out nothing, only the >>>.
Thanks in advance!
import requests
url = 'http://example.com/files/'
user, password = 'ex', 'ample'
files = {'upload_file': open(r'C:\Users\example\Desktop\code\de.txt','rb')}
r = requests.post(url, auth=(user, password), files=files)
Writing a file across network
import requests
from requests.auth import HTTPBasicAuth
url = 'http://example.com/files/'
user, password = 'ex', 'ample'
files = {'file': ('de.txt', open('de.txt', 'rb'), 'multipart/form-data', {'Expires': '0'})}
r = requests.post(url, auth=HTTPBasicAuth(user, password), files=files)
For reference use Python Request documentation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.