问题描述
如何使用python3将zip文件上传到我的Apache WEB DAV服务器?
import requests
from requests.auth import HTTPBasicAuth
files = open('MysqLSupplyCollector.zip','rb')
url = 'http://example.com/webdav/'
r = requests.put(url,files={"archive": files},auth = HTTPBasicAuth('test','qwerty'))
print(r.text)
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>409 Conflict</title>
</head><body>
<h1>Conflict</h1>
<p>Cannot PUT to a collection.</p>
<hr />
<address>Apache/2.4.29 (Ubuntu) Server at example.com Port 80</address>
</body></html>
解决方法
您需要将网址从http://example.com/webdav/
更改为http://example.com/webdav/MySqlSupplyCollector.zip
。
目标必须是文件,而不是文件夹(集合)。
某些DAV服务器甚至要求您将文件保存在根目录中,而不是在其子目录中。