这个命令用 requests 怎么写?

2020-12-06 18:24:26 +08:00
 imn1
curl -X PROPFIND -u login -H "Content-Type: text/xml" -H "Depth: 1" \
--data "<propfind xmlns='DAV:'><prop><calendar-data xmlns='urn:ietf:params:xml:ns:caldav'/></prop></propfind>" \
https://myserver/joe/home/

谢了 🌺
2975 次点击
所在节点    Python
8 条回复
aonshuy
2020-12-06 18:31:41 +08:00
imn1
2020-12-06 18:35:07 +08:00
@aonshuy
这年头真是只有想不到的…… 🌻
justin2018
2020-12-06 18:36:06 +08:00
https://curl.trillworks.com/

import requests

headers = {
'Content-Type': 'text/xml',
'Depth': '1',
}

data = {
'<propfind xmlns': '\'DAV:\'><prop><calendar-data xmlns=\'urn:ietf:params:xml:ns:caldav\'/></prop></propfind>'
}

response = requests.post('https://myserver/joe/home/', headers=headers, data=data, auth=('login', ''))
ysc3839
2020-12-06 18:37:12 +08:00
@aonshuy @justin2018
这个网站转出来似乎是错的,忽略了 PROPFIND method 。
no1xsyzy
2020-12-06 18:54:11 +08:00
@ysc3839 去提个 issue 呗
临时解决的话,应该还是用 requests.request('PROPFIND', ...)
除此以外,直接 PyPI 上找找 WebDAV 库呗
imn1
2020-12-06 19:27:27 +08:00
@no1xsyzy #5
没搜到 py3 可用的 carddav,caldav 那个还好,只是它仅有 caldav,代码看得有点晕,想继成过来兼容 carddav 没搞定
只是我需求没那么复杂,自用不需要理会各种 rfc 标准,分析出字段能读能写就行,requests + vobject 就够了
vone
2020-12-06 23:40:16 +08:00
你命令里的 "-u login" 不知道为什么被 postman 忽略了,改为 "-u login:",然后导入 postman,然后生成代码如下:

import requests

url = "https://myserver/joe/home/"

payload="<propfind xmlns='DAV:'><prop><calendar-data xmlns='urn:ietf:params:xml:ns:caldav'/></prop></propfind>"
headers = {
'Content-Type': 'text/xml',
'Depth': '1',
'Authorization': 'Basic bG9naW46'
}

response = requests.request("PROPFIND", url, headers=headers, data=payload)

print(response.text)


postman 导入方式:主界面=> Import => Raw text => Continue 。

https://i.loli.net/2020/12/06/5gvcKAYo1qEhrHR.jpg
https://i.loli.net/2020/12/06/9m4abLBcCuysv1W.jpg
WordTian
2020-12-07 01:41:23 +08:00
WEBDAV 是 HTTP 的协议扩展,requests 是 http 的库,理论上应该不支持的吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/732684

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX