Python script to export Csv using API fails to export

Hello,

I would like to use PythonOmekaApiToCsv script to export items from Omeka to csv.

The script works fine on a Omeka test installation with few items but fails to export another omeka site with a lot more items. I have the following error:

$ ./omekacsv.py 
Enter your Omeka API endpoint
http://myomeka/api
If you are using an API key, please enter it now. Otherwise press Enter.

Exporting items
Getting results page 1 of 25 ...
Traceback (most recent call last):
  File "./omekacsv.py", line 65, in <module>
    get_all_pages(pages)
  File "./omekacsv.py", line 54, in get_all_pages
    data.extend(json.loads(content))
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

I am using Python 2.7.13. I also tested omekadd script which offers the same functionality with omekacsv.py (PythonOmekaApiToCsv is a fork of omekacsv) with the same error.

Hard to tell, but my first guess is that the larger installation has some quirk that makes it produce invalid JSON data from the API. It looks from the URL (http://myomeka/api) like it isn’t publicly available. When you go to that URL in your browser, what’s the data returned?

Thanks for the answer.

If I go to the myomeka/api/ it offers me to view site informations and available api ressources.

Here are the available api ressources page (/api/resources?pretty_print):

{
	"site":{
		"controller":"site",
		"actions":[
			"index"
		],
		"url":"http:\/\/myomeka\/api\/site"
	},
	"resources":{
		"controller":"resources",
		"actions":[
			"index"
		],
		"url":"http:\/\/myomeka\/api\/resources"
	},
	"collections":{
		"record_type":"Collection",
		"actions":[
			"index",
			"get",
			"post",
			"put",
			"delete"
		],
		"index_params":[
			"public",
			"featured",
			"added_since",
			"modified_since",
			"owner"
		],
		"url":"http:\/\/myomeka\/api\/collections"
	},
	"items":{
		"record_type":"Item",
		"actions":[
			"index",
			"get",
			"post",
			"put",
			"delete"
		],
		"index_params":[
			"collection",
			"item_type",
			"featured",
			"public",
			"added_since",
			"modified_since",
			"owner",
			"tags",
			"excludeTags",
			"hasImage",
			"range"
		],
		"url":"http:\/\/myomeka\/api\/items"
	},
	"files":{
		"controller":"files",
		"record_type":"File",
		"actions":[
			"index",
			"get",
			"post",
			"put",
			"delete"
		],
		"index_params":[
			"item",
			"order",
			"size_greater_than",
			"has_derivative_image",
			"mime_type",
			"modified_since",
			"added_since"
		],
		"url":"http:\/\/myomeka\/api\/files"
	},
	"item_types":{
		"record_type":"ItemType",
		"actions":[
			"index",
			"get",
			"post",
			"put",
			"delete"
		],
		"index_params":[
			"name"
		],
		"url":"http:\/\/myomeka\/api\/item_types"
	},
	"elements":{
		"record_type":"Element",
		"actions":[
			"index",
			"get",
			"post",
			"put",
			"delete"
		],
		"index_params":[
			"element_set",
			"name",
			"item_type"
		],
		"url":"http:\/\/myomeka\/api\/elements"
	},
	"element_sets":{
		"record_type":"ElementSet",
		"actions":[
			"index",
			"get",
			"post",
			"delete"
		],
		"index_params":[
			"name",
			"record_type"
		],
		"url":"http:\/\/myomeka\/api\/element_sets"
	},
	"users":{
		"record_type":"User",
		"actions":[
			"get"
		],
		"url":"http:\/\/myomeka\/api\/users"
	},
	"tags":{
		"record_type":"Tag",
		"actions":[
			"index",
			"get",
			"delete"
		],
		"url":"http:\/\/myomeka\/api\/tags"
	},
	"simple_pages":{
		"record_type":"SimplePagesPage",
		"actions":[
			"get",
			"index"
		],
		"url":"http:\/\/myomeka\/api\/simple_pages"
	}
}

I don’t know if it is relevant. I can send you the link to the website by private message if you want.

Thanks. The first page, at least looks okay at first glance. The next page to check and report back the results is api/items. Seems like on the first page there should be something that looks wrong on that page.