{"record":{"id":"4e4e0f60c3817489","repo":"HumanSignal/label-studio","slug":"load-tasks-no-data-found-in-data-or-in-files","errorCode":null,"errorMessage":"load_tasks: No data found in DATA or in FILES","messagePattern":"load_tasks: No data found in DATA or in FILES","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_import/api.py","lineNumber":409,"sourceCode":"            if not url:\n                raise ValidationError('\"url\" is not found in request data')\n            if len(url) > 2048:\n                raise ValidationError('\"url\" must be 2048 characters or fewer')\n            project_import.url = url\n            project_import.save(update_fields=['url'])\n        # take one task from request DATA\n        elif 'application/json' in request.content_type and isinstance(request.data, dict):\n            project_import.tasks = [request.data]\n            project_import.save(update_fields=['tasks'])\n\n        # take many tasks from request DATA\n        elif 'application/json' in request.content_type and isinstance(request.data, list):\n            project_import.tasks = request.data\n            project_import.save(update_fields=['tasks'])\n\n        # incorrect data source\n        else:\n            raise ValidationError('load_tasks: No data found in DATA or in FILES')\n\n        start_job_async_or_sync(\n            async_import_background,\n            project_import.id,\n            request.user.id,\n            queue_name='high',\n            on_failure=set_import_background_failure,\n            project_id=project.id,\n            organization_id=request.user.active_organization.id,\n        )\n\n        response = {'import': project_import.id}\n        return Response(response, status=status.HTTP_201_CREATED)\n\n    def create(self, request, *args, **kwargs):\n        commit_to_project = bool_from_request(request.query_params, 'commit_to_project', True)\n        return_task_ids = bool_from_request(request.query_params, 'return_task_ids', False)\n        preannotated_from_fields = list_of_strings_from_request(request.query_params, 'preannotated_from_fields', None)","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_import/api.py#L391-L427","documentation":"async_import dispatches on request content type: file upload (multipart), urlencoded url import, or JSON body with tasks. If none of these branches matched — no FILES, not urlencoded, and body not a JSON list/dict of tasks — it falls into the 'incorrect data source' else branch and raises this ValidationError. It is the 'we received nothing importable' error.","triggerScenarios":"POST /api/projects/{id}/import with an empty body; Content-Type application/json but body is an empty string, an empty dict with no recognizable task data handled by earlier branches, or a non-dict/non-list scalar (e.g. plain text body); missing multipart file field with no other data.","commonSituations":"Client sends JSON with Content-Type: application/json but body serialized as a string of text rather than a JSON array/object; upload script posts a form without the file part; gateway/proxy strips the request body; automation passing an empty list after an upstream job produced no tasks; sending text/csv body with an unsupported content type.","solutions":["Send tasks as a JSON array: requests.post(url, json=[{...task...}]) so Content-Type and body match","If importing a file, send it as multipart/form-data with the file part (requests files= parameter)","If importing from a URL, use application/x-www-form-urlencoded with a non-empty 'url' field","Log/inspect the exact request body and Content-Type actually sent (curl -v) to see which branch failed","Ensure upstream data generation is not producing an empty payload"],"exampleFix":"# before: string body treated as neither list nor dict\nrequests.post(url, headers={'Content-Type': 'application/json'}, data='{\"data\": {}}')\n# after: proper JSON list of tasks\nrequests.post(url, json=[{\"data\": {\"text\": \"hello\"}}])","handlingStrategy":"validation","validationCode":"assert tasks and isinstance(tasks, list), 'payload must be a non-empty JSON list of tasks'\nassert all(isinstance(t, dict) and 'data' in t for t in tasks), 'each task must be an object with a data key'","typeGuard":"def is_valid_import_payload(body) -> bool:\n    return isinstance(body, list) and len(body) > 0 and all(isinstance(i, dict) for i in body)","tryCatchPattern":"try:\n    resp = requests.post(import_url, headers=H, json=tasks)\n    resp.raise_for_status()\nexcept requests.HTTPError as e:\n    if 'No data found in DATA or in FILES' in e.response.text:\n        log.error('Body/Content-Type mismatch: sent %r %r', req_content_type, req_body_preview)","preventionTips":["Always pair requests json= (or files=) with the matching Content-Type","Log the final serialized body when debugging import failures","Fail fast in pipelines when upstream produces zero tasks","Verify proxies/gateways do not strip request bodies"],"tags":["django","rest-framework","import","request-body","content-type"],"backgroundTag":"empty-request-body","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}