Pradeep Chandran
Pradeep Chandran

Reputation: 337

WebDAV file upload with python3

how can I upload a zip file to my apache WEB DAV server using python3?

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)

tried the above code but getting an error

<!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>

Upvotes: 0

Views: 4611

Answers (1)

J&#252;rgen Gmach
J&#252;rgen Gmach

Reputation: 6123

You need to change your URL from http://example.com/webdav/ to http://example.com/webdav/MySqlSupplyCollector.zip.

The target needs to be a file, not a folder (collection).

Some DAV servers even require that you save files not in the root directory, but in a subdirectory of it.

Upvotes: 1

Related Questions