我想使用its REST api与seafile服务器进行交互。
到目前为止,将POST或GET查询转换为ansuri uri模块没有问题。但是,我无法使PUT查询正常工作。
以下适用于curl:
curl -X PUT -d "share_type=group&group_id=<groupid>&permission=rw" -H 'Authorization: Token <mysecrettoken>' -H 'Accept: application/json; charset=utf-8; indent=4' https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/
当我将其翻译为以下任务时,它将失败:
- name: mytask
uri:
url: "https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/"
method: PUT
headers: '{ "Authorization": "Token <mysecrettoken>" }'
body: '{ "share_type": "group", "group_id": "<groupid>", "permission": "rw"}'
body_format: json
return_content: yes
我得到了错误:
HTTP Error 500: INTERNAL SERVER ERROR", "redirected": false, "server": "nginx", "set_cookie": "SERVERID=<serverid>; path=/", "status": 500, "transfer_encoding": "chunked", "url": "https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/", "vary": "Accept-Language, Cookie"}
在使用请求库的python脚本中,我必须提供最后的?p=/
作为params={'p': '/'}
。这是失败的原因吗?那么如何正确提交参数?
答案 0 :(得分:1)
您应该将headers
作为YAML哈希而不是JSON字符串传递:
- name: mytask
uri:
url: "https://<myserverurl>/api2/repos/<mylibraryid>/dir/shared_items/?p=/"
method: PUT
headers:
Authorization: "Token <mysecrettoken>"
body: '{ "share_type": "group", "group_id": "<groupid>", "permission": "rw"}'
body_format: json
return_content: yes
有关参考,请参见the docs,尤其是倒数第二个示例:
- uri:
url: https://your.form.based.auth.example.com/dashboard.php
method: GET
return_content: yes
headers:
Cookie: "{{ login.set_cookie }}"