Update app.py
Browse files
app.py
CHANGED
@@ -529,7 +529,7 @@ def webdav_upload(filename, data):
|
|
529 |
headers = {'Content-Type': 'application/json'}
|
530 |
|
531 |
try:
|
532 |
-
|
533 |
dir_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}")
|
534 |
response = requests.request('MKCOL', dir_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD))
|
535 |
if response.status_code == 201:
|
@@ -539,22 +539,9 @@ def webdav_upload(filename, data):
|
|
539 |
elif response.status_code != 409:
|
540 |
response.raise_for_status()
|
541 |
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
if check_response.status_code == 207:
|
546 |
-
print(f"WebDAV 文件已存在,使用PUT更新: {filename}")
|
547 |
-
response = requests.put(url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), data=json.dumps(data, default=str), headers=headers)
|
548 |
-
response.raise_for_status()
|
549 |
-
else:
|
550 |
-
print(f"WebDAV 文件不存在,使用COPY创建: {filename}")
|
551 |
-
copy_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}{filename}.tmp")
|
552 |
-
response = requests.put(copy_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), data=json.dumps(data, default=str), headers=headers)
|
553 |
-
response.raise_for_status()
|
554 |
-
response = requests.request('COPY', copy_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), headers={'Destination': url})
|
555 |
-
response.raise_for_status()
|
556 |
-
response = requests.request('DELETE', copy_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD))
|
557 |
-
response.raise_for_status()
|
558 |
print(f"WebDAV 上传成功: {filename}")
|
559 |
|
560 |
except requests.exceptions.RequestException as e:
|
|
|
529 |
headers = {'Content-Type': 'application/json'}
|
530 |
|
531 |
try:
|
532 |
+
#尝试创建目录
|
533 |
dir_url = urljoin(WEBDAV_URL, f"{WEBDAV_DIR}")
|
534 |
response = requests.request('MKCOL', dir_url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD))
|
535 |
if response.status_code == 201:
|
|
|
539 |
elif response.status_code != 409:
|
540 |
response.raise_for_status()
|
541 |
|
542 |
+
# 直接尝试PUT上传文件
|
543 |
+
response = requests.put(url, auth=(WEBDAV_USERNAME, WEBDAV_PASSWORD), data=json.dumps(data, default=str), headers=headers)
|
544 |
+
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
print(f"WebDAV 上传成功: {filename}")
|
546 |
|
547 |
except requests.exceptions.RequestException as e:
|