问题
I'm doing some tests with demo.ckan.org
, which is running the 2.4 version of the API, AFAIK. Everything works well (organization and dataset creation) except for the resource creation. The resource_create
method always returns a 500
error.
This is the curl
showing the package where I want to create the resource:
$ curl -X GET "http://demo.ckan.org:80/api/3/action/package_show?id=f2c4125b-27c8-4e07-94d7-d6d0c0b65154" | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1228 100 1228 0 0 1384 0 --:--:-- --:--:-- --:--:-- 1386
{
"help": "http://demo.ckan.org/api/3/action/help_show?name=package_show",
"result": {
"author": null,
"author_email": null,
"creator_user_id": "b0a12b23-4cee-4d8c-993e-723421a0a296",
"extras": [],
"groups": [],
"id": "f2c4125b-27c8-4e07-94d7-d6d0c0b65154",
"isopen": false,
"license_id": null,
"license_title": null,
"maintainer": null,
"maintainer_email": null,
"metadata_created": "2015-09-29T14:09:21.629953",
"metadata_modified": "2015-09-29T14:09:21.669256",
"name": "frb_org_test1_frb_pkg_test2",
"notes": null,
"num_resources": 0,
"num_tags": 0,
"organization": {
"approval_status": "approved",
"created": "2015-09-29T10:55:53.479724",
"description": "",
"id": "402f83c1-0070-4694-a1d9-f25b1d114631",
"image_url": "",
"is_organization": true,
"name": "frb_org_test1",
"revision_id": "26993878-9024-429a-b753-cc087b0ce382",
"state": "active",
"title": "",
"type": "organization"
},
"owner_org": "402f83c1-0070-4694-a1d9-f25b1d114631",
"private": false,
"relationships_as_object": [],
"relationships_as_subject": [],
"resources": [],
"revision_id": "47acfd70-8d26-4ebb-8cbd-6cababc627b1",
"state": "active",
"tags": [],
"title": "frb_org_test1_frb_pkg_test2",
"type": "dataset",
"url": null,
"version": null
},
"success": true
}
And the curl
failing when trying to create the resource:
$ curl -X POST "http://demo.ckan.org:80/api/3/action/resource_create" -d '{ "name": "room1_room", "url": "none", "package_id": "f2c4125b-27c8-4e07-94d7-d6d0c0b65154" }' -H "Authorization: MY_API_KEY_IS_SECRET"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
[no address given] and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at demo.ckan.org Port 80</address>
</body></html>
回答1:
This appears to be a documentation (and code) bug.
Although format is marked as optional in the documentation, the code requires it to be present (and will unfortunately crash if it isn't).
I've created a ticket at https://github.com/ckan/ckan/issues/2665
As a temporary measure until this is fixed, you can specify the "format" in the JSON you send (it can be empty).
来源:https://stackoverflow.com/questions/32860432/not-able-to-create-a-resource-in-demo-ckan-org-through-the-api-500-error