我有一个文件附件,我正在尝试通过REST API上传到Confluence。我可以通过复制他们的示例使用curl来完成,但是当使用Ansible时失败了,我无法弄清楚原因。
这是curl命令:
这是curl命令:
curl -u <username>:<password> -X POST -H "X-Atlassian-Token: nocheck" -F "file=@<filepath>" -F "comment=File attached via REST API" https://myconfluenceserver.com/rest/api/content/<page ID>/child/attachment
当然,<>
中的值会被替换为实际值。这个命令执行成功。
这是 Ansible
任务:
ansible.builtin.uri:
user: "{{ osa_credentials.username }}"
password: "{{ osa_credentials.password }}"
url: "{{ url }}"
method: POST
headers:
X-Atlassian-Token: nocheck
force_basic_auth: yes
src: "{{ filepath }}"
validate_certs: no
当我运行curl
命令时可以工作,但是使用Ansible时会抛出错误400
。以下是完整的错误信息:
fatal: [localhost]: FAILED! => {
"changed": false,
"connection": "close",
"content_language": "en",
"content_length": "435",
"content_type": "text/html;charset=utf-8",
"date": "Thu, 29 Jun 2023 06:34:10 GMT",
"elapsed": 1,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"ciphers": null,
"client_cert": null,
"client_key": null,
"creates": null,
"decompress": true,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": true,
"group": null,
"headers": {
"Content-Length": 543818,
"X-Atlassian-Token": "nocheck"
},
"http_agent": "ansible-httpget",
"method": "POST",
"mode": null,
"owner": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"remote_src": false,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": "<filepath>",
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unredirected_headers": [],
"unsafe_writes": true,
"url": "https://myconfluenceserver.com/rest/api/content/<page ID>/child/attachment",
"url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"url_username": "<username>",
"use_gssapi": false,
"use_netrc": true,
"use_proxy": true,
"user": "<username>",
"validate_certs": false
}
},
"msg": "Status code was 400 and not [200]: HTTP Error 400: ",
"redirected": false,
"server": "Apache",
"status": 400,
"url": "https://myconfluenceserver.com/rest/api/content/<page ID>/child/attachment"
}
我错过了什么?
状态码为400而不是[200]:HTTP错误400
。 - jeremywatsrc: "{{ filepath }}"
中定义的响应文件是否包含API所期望的所有内容吗?例如,文件内容的file
表单字段和上传评论的comment
字段。 Confluence服务器上是否有任何有用的日志可以帮助调试Ansible缺少的问题? - Byobsrc: "{{ filepath }}"
是我作为附件上传的文件。它不包含file
、comment
或其他任何字段。不幸的是,由于我只是Confluence的用户,我无法访问Confluence日志。 - jeremywat