我想上傳文件到服務器使用python。這意味着在這種情況下,當我在瀏覽器中編寫http://example.com/files/時,我希望在文件列表中看到de.txt。我應該如何改變這個腳本才能工作?當我運行它時,python shell什麼也沒有寫,只有>>>。上傳文件到服務器不工作在python
在此先感謝!
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)
的可能重複https://stackoverflow.com/questions/22567306/python-requests-file-upload – amrit