TypeError when using PythonOmekaApiToCsv

I’m trying to use GitHub - omeka/PythonOmekaApiToCsv: Python script for exporting metadata from Omeka to a CSV file via the Omeka API.. The script starts to run, showing progress to get results for pages 1-256, but right after 256, it throws this error:
Traceback (most recent call last):
File “[…]PythonOmekaApiToCsv-master/omekacsv.py”, line 129, in
csv_row[element_header] = multivalue_separator.join(texts)
TypeError: sequence item 0: expected str instance, NoneType found

Should I tweak something in the script to avoid this error? Thanks for any help!

Hmm… can you share the API endpoint you were using?

That would help a lot in determining what’s causing this.

Sure, it is: http://history.library.gatech.edu/api/ Thank you!

It looks like the problem is a handful of items that have “null” element texts. If you check the repository for the script, I’ve pushed an update that should solve your problem.

Wonderful, thank you so much!! The items_output.csv generated just fine. I get this error at the end of the process that generates files_output.csv:

File …“PythonOmekaApiToCsv-master 2/omekacsv.py”, line 165, in
c.writerow(row)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/csv.py”, line 154, in writerow
return self.writer.writerow(self._dict_to_list(rowdict))
_csv.Error: need to escape, but no escapechar set

I didn’t encounter that issue but I’ll look again. It’s possible it’s something I just didn’t notice, or maybe it’s a Mac-specific problem.

The default CSV settings should be quoting fields, not escaping, so this is a somewhat odd error message.

I’ve tried to reproduce it again myself and had someone else try on a Mac: no results, we both don’t get any error in generating the files CSV.

Are you using a key when you run the script? It’s possible that if you have some data that causes this problem and it’s on a private item/file then you would only encounter it when using a key. But I’m still somewhat flummoxed on the problem itself… it really shouldn’t be happening as far as I can tell.

It looks like from your output that you’re using Python 3.10, is that right? We’ve tried to reproduce on Python 3.8 and 3.9 installs, so it’s also possible that the problem is specific to Python 3.10.

Thank you so much for your help! Yes, I’m using Python 3.10 on Mac, and without an API key. Actually, I think the items_output.csv provided all of the info I need, so I think I’m all set. I so appreciate your help.

This topic was automatically closed after 250 days. New replies are no longer allowed.