kobotoolbox / kobocat

Our (backend) server for providing blank forms to Collect and Enketo and for receiving and storing submissions.
BSD 2-Clause "Simplified" License
117 stars 127 forks source link

HTTP/500 error when using csv_import API call #907

Open frenzymadness opened 1 year ago

frenzymadness commented 1 year ago

Description

I’m trying to import some data to an existing form and the response I’m getting from API is HTTP/500 with full HTML content which is not expected from an API.

Steps to Reproduce

  1. Create a form.
  2. Add a response to it.
  3. Use API to export a CSV from it. Something like curl -v -X GET https://kc.kobotoolbox.org/api/v1/forms/XXX.csv
  4. Remove the response from the form data to prevent duplicates (probably an optional step)
  5. Use API to import previously exported CSV back. Something like curl -v -X POST https://kc.kobotoolbox.org/api/v1/forms/XXX/csv_import -u "user:pass" -F csv_file=@/home/user/XXX.csv

Expected behavior

Import is successful and if there is an error in the imported data, a meaningful error message is returned by the API.

Actual behavior

HTML page with HTTP/500 error.

Additional details

I need to import a few hundred of responses from our previous system so I wanted to learn about the structure of the CSV file expected by the kobo toolbox for the given form so I thought that the simple export/import should work. Is there any documentation of what should be in the CSV file one wants to import? It's obvious for responses to the questions from the form but less obvious for columns like _id or _uuid.

frenzymadness commented 1 year ago

I've might found the code handling this in: https://github.com/kobotoolbox/kobocat/blob/72145d78e33818bae06c7cd8a376fe23deb95f97/onadata/libs/utils/csv_import.py#L61

I've tried to create a minimal reproducer, but the following lines work fine with the exported file:

>>> import unicodecsv as ucsv
>>> csv_file = open("XXX.csv", mode="rb")
>>> csv_reader = ucsv.DictReader(csv_file)
>>> for row in csv_reader:
...   print(row)
...
noliveleger commented 1 year ago

Hello @frenzymadness,

This issue is related to Kobocat and API v1 which has been deprecated for a while. Please open an issue there https://github.com/kobotoolbox/kobocat/ and close this one. TBH, the error may not be fixed (since the API is deprecated) or will be considered a (very) low priority and may take a while.

Due to the small size of our team and large volume of users, we cannot provide support or guidance via GitHub issues. Please use the community forum to seek for help.

frenzymadness commented 1 year ago

Thank you very much for the response. I had a discussion about this on the community forum and it seems that csv import is really not functioning properly now. What is kinda confusing to me is that if v1 of API is deprecated, where I can find documentation for v2? When I try to visit https://kc.kobotoolbox.org/api/v2/ it redirects me back to v1 and there id no notice about it being deprecated.

noliveleger commented 1 year ago

API v2 is located at https://kf.kobotoolbox.org/api/v2/ (different domain name)

jnm commented 1 year ago

I've transferred the issue to the appropriate repository.