Search code examples
python-requestsartifactory

415 Unsupported Media Type in Artifactory AQL POST


Probably a simple mistake but I get a 415 Unsupported Media Type error with this simple Artifactory AQL POST. I get the same error regardless of whether I include the content-type header.

#!/usr/local/bin/python
import requests
import json

username = "admin"
password = "password"
url = "http://myhost:8081/artifactory/api/search/aql"

r = requests.post(url, auth=(username, password), headers={"content-type":"application/json"}, json='{items.find( { "repo":{"$eq":"test-repo"} })}')

if r.status_code == 200:
    print "Success!\n"
    print r.content
else:
    print "Fail\n"
    print r.text

{ "errors" : [ { "status" : 415, "message" : "Unsupported Media Type" } ] }


Solution

  • AQL is not JSON. The text inside the items.find(...) is formatted as JSON, but the entire query as a whole doesn't follow the JSON standard. The expected content type is text/plain.

    Also, instead of json='{items.find( { "repo":{"$eq":"test-repo"} })}', you should use data='items.find( { "repo":{"$eq":"test-repo"} })'.