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" } ] }
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.
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.
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"} })'
.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With