python - 如何在 Python 中的 POST 请求中将查询作为正文发送

标签 python python-2.7 python-requests artifactory

我正在尝试将人工查询作为主体发送到 POST 方法。我总是得到 400 的响应(这是一个错误的请求)。这是我的代码。我在这里做错了什么。查询看起来很好它可以使用curl 也可以使用Groovy。

host = http://artifactory.com/artifactory
build_url = '%s/api/search/aql' % (host)
payload='{items.find({"repo":"lib","type":"file","path":"builds"}).include("*"}'
response = requests.post(build_url,data=payload,auth=(user:pwd))
print response

输出: 响应 [400]

我使用的是 Python 2.7,这里是 REST API 详细信息

Artifactory Query Language (AQL) REST API
Since: 3.5.0
Security: Requires an authenticated user
Usage: POST /api/search/aql
Consumes: text/plain

--提前致谢

最佳答案

我认为您只是在 include("*" 之后缺少一个括号。试试这个:

payload='{items.find({"repo":"lib","type":"file","path":"builds"}).include("*")}'

编辑:根据讨论,问题是缺少身份验证。

关于python - 如何在 Python 中的 POST 请求中将查询作为正文发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34365607/

相关文章:

python - var == False 或如果不是 var

python - 链接 Python3 的 Openssl-FIPS 库

python - 如何在redis中存储多个字段并根据某些字段获得前10名的结果

python - 将值附加到列表并添加到字典

python - Twisted html 文件列表给出 "Request did not return bytes"错误

python - Python 网页抓取时的编码问题

javascript - 无法根据下拉选项更新同一页面

Python:SystemError 父模块未加载,无法执行相对导入

python - 如何实现这个python post并获取?

python - 如何在 python 的 POST 请求中将 null 作为值传递?