Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" } ] }

like image 956
John Avatar asked Sep 18 '18 21:09

John


People also ask

How do I fix HTTP 415 unsupported media type?

Fixing 415 Unsupported Media Type errorsEnsure that you are sending the proper Content-Type header value. Verify that your server is able to process the value defined in the Content-Type header. Check the Accept header to verify what the server is actually willing to process.

What is a 415 HTTP?

The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format. The format problem might be due to the request's indicated Content-Type or Content-Encoding , or as a result of inspecting the data directly.


2 Answers

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"} })'.

like image 132
DarthFennec Avatar answered Oct 26 '22 03:10

DarthFennec


I stumbled at the same issue, it worked when I changed the content type to 'text/plain'. Just to augment @DarthFennec's answer, providing what the official REST API documentation quotes:

Sample Usage:

POST /api/search/aql

items.find(
    {
        "repo":{"$eq":"libs-release-local"}
    }
)

Produces: application/json Sample Output:

{
    "results" : [
    {
        "repo" : "libs-release-local",
        "path" : "org/jfrog/artifactory",
        "name" : "artifactory.war",
        "type" : "item type",
        "size" : "75500000",
        "created" : "2015-01-01T10:10;10",
        "created_by" : "Jfrog",
        "modified" : "2015-01-01T10:10;10",
        "modified_by" : "Jfrog",
        "updated" : "2015-01-01T10:10;10"
    }
    ],
    "range" : {
    "start_pos" : 0,
    "end_pos" : 1,
    "total" : 1
    }
}

Note that the Content-type signifies the type(format) of the data in the request(so as per doc., it expects text/plain) while Accept notifies about the expected response(here, the artifactory will return json).

like image 36
Kaliyug Antagonist Avatar answered Oct 26 '22 04:10

Kaliyug Antagonist