I am using the script attached to perform this task but unfortunately, I get the Error 500 every time I do so.
I have tried copying and pasting the JSON data as well onto the kc.kobotoolbox.org/api/v1/submissions page and I still get the same error 500.
The Python script producing this error is below.
import requests
import json
def post_data_to_kobo(form_id, submission_data, username, password):
url = f"https://kc.kobotoolbox.org/api/v1/submissions"
auth = (username, password)
data = {
"id": form_id,
"submission": submission_data
}
headers = {
"Content-Type": "application/json"
}
try:
response = requests.post(url, json=data, auth=auth, headers=headers)
if response.status_code == 201:
print("Data submission successful!")
else:
print(f"Data submission failed with status code: {response.status_code}")
print(response.text)
except requests.exceptions.RequestException as e:
print("An error occurred during the data submission:")
print(e)
if __name__ == "__main__":
# Replace the following variables with your actual data
form_id = "<my_form_id>"
submission_data_file = "census.json"
username = "<my_username>"
password = "<my_password>"
with open(submission_data_file) as file:
submission_data = json.load(file)
post_data_to_kobo(form_id, submission_data, username, password)
Unfortunately, it seems I am not allowed to paste attachments as a new user but the JSON looks like this.
[
{
"172938293": 172938293,
"start": "end"
},
{
"172938293": "3/8/2023",
"start": "Date"
},
{
"172938293": "",
"start": "location_note"
},
{
"172938293": "ZW",
"start": "country"
},
{
"172938293": "ZW13",
"start": "adm_one"
},
{
"172938293": "ZW1303",
"start": "adm_two"
},
{
"172938293": "ZW130309",
"start": "adm_three"
},
{
"172938293": "",
"start": "adm_four"
},
{
"172938293": "Example Village",
"start": "Village_Name"
},
{
"172938293": "-19.947651666666665 30.6872 1183.2 21.125",
"start": "Location_Coordinates"
},
{
"172938293": -19.94765167,
"start": "_Location_Coordinates_latitude"
},
{
"172938293": 30.6872,
"start": "_Location_Coordinates_longitude"
},
{
"172938293": 1183.2,
"start": "_Location_Coordinates_altitude"
},
{
"172938293": 21.125,
"start": "_Location_Coordinates_precision"
},
{
"172938293": "rtsl",
"start": "Pillar"
},
{
"172938293": "rra",
"start": "Project"
},
{
"172938293": "farmers",
"start": "Types_of_Participants"
},
{
"172938293": "",
"start": "Other_Participant_Type"
},
{
"172938293": "",
"start": "Group_Name"
},
{
"172938293": 13105,
"start": "random_number"
},
{
"172938293": "ZW1303_223700626",
"start": "Participant_ID"
},
{
"172938293": "Person Name",
"start": "Full_name"
},
{
"172938293": "Male",
"start": "Gender"
},
{
"172938293": "6/2/1982",
"start": "Date_of_Birth"
},
{
"172938293": "",
"start": "Age"
},
{
"172938293": 41,
"start": "participant_age"
},
{
"172938293": "ordinary",
"start": "Position"
},
{
"172938293": "",
"start": "Organisation"
},
{
"172938293": 7392,
"start": "National_ID_Number"
},
{
"172938293": 7712345687,
"start": "Mobile_Phone_Number"
},
{
"172938293": "ZW",
"start": "Country"
},
{
"172938293": "",
"start": "Specify"
},
{
"172938293": 223700626,
"start": "_id"
},
{
"172938293": "32780e14-9c5f-49e8-b568-ec37e0153849",
"start": "_uuid"
},
{
"172938293": "########",
"start": "_submission_time"
},
{
"172938293": "",
"start": "_validation_status"
},
{
"172938293": "",
"start": "_notes"
},
{
"172938293": "submitted_via_web",
"start": "_status"
},
{
"172938293": "",
"start": "_submitted_by"
},
{
"172938293": "vApGFsoZmEWyyUVW7igvCj",
"start": "__version__"
},
{
"172938293": "",
"start": "_tags"
},
{
"172938293": 7778,
"start": "_index"
}
]
Any assistance would be appreciated.
I also tried this solution available here - Data import though Python but server did not accept the data when edit - User Support / API - KoboToolbox Community Forum but I get an error that says:
InvalidJSONError: Out of range float values are not JSON compliant