可能是一个简单的错误,但是通过此简单的Artifactory AQL POST,我收到415 Unsupported Media Type错误。无论是否包含content-type标头,都会出现相同的错误。
#!/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
{“错误”:[{“状态”:415,“消息”:“不支持的媒体类型”}]}
AQL不是JSON。内的文字items.find(...)
格式为JSON,但整个查询整体上并未遵循JSON标准。预期的内容类型为text/plain
。
另外,json='{items.find( { "repo":{"$eq":"test-repo"} })}'
您应该使用代替data='items.find( { "repo":{"$eq":"test-repo"} })'
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句