简体   繁体   中英

How to send a Query as a body in the POST request in Python

I am trying to send an artifactory Query as a body to a POST Method.I always get the response as 400(Which is a Bad request).Here is my code.What am I doing wrong here.Query looks good as it works using curl and also using 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

output: Response [400]

I am using Python 2.7 and here are the REST API Details

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

--Thanks in advance

I think you are just missing a parenthesis at the end, after include("*" . Try this:

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

Edit: According to the discussion, the problem was lack of authentication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM