doccano-client icon indicating copy to clipboard operation
doccano-client copied to clipboard

Uploading the file from the API fails

Open ChiLynn123 opened this issue 5 years ago • 8 comments

Hello, I made an error uploading the document using the API, but the document can appear in the Doccano instance database. Looking forward to your reply to my questions, thank you very much!

r_du = doccano_client.post_doc_upload(8, "json", "fail1.json", "D:\WPSCloud")

error: Traceback (most recent call last): File "D:/doccano/doccano-client/doccano_api_client/example.py", line 113, in r_du = doccano_client.post_doc_upload(8, "csv", "data_xa.csv", "D:\WPSCloud") File "D:\doccano\doccano-client\doccano_api_client_init_.py", line 521, in post_doc_upload data=data File "D:\doccano\doccano-client\doccano_api_client_init_.py", line 64, in post request_url, data=data, files=files, json=json).json() File "E:\Anaconda\lib\site-packages\requests\models.py", line 885, in json return complexjson.loads(self.text, **kwargs) File "E:\Anaconda\lib\json_init_.py", line 354, in loads return _default_decoder.decode(s) File "E:\Anaconda\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "E:\Anaconda\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

ChiLynn123 avatar Sep 28 '20 03:09 ChiLynn123

Please paste an example of your file.

Hironsan avatar Sep 28 '20 04:09 Hironsan

I can't upload a file in JSON format, Please try converting this file to JSON format.thanks very much! example.txt

ChiLynn123 avatar Sep 28 '20 07:09 ChiLynn123

I used CSV or JSON modules to generate standard CSV and JSON document invocation API interface, which also failed to upload.But this data can be seen in a database on the Web side.

ChiLynn123 avatar Sep 28 '20 07:09 ChiLynn123

Same issue here. The doccano client returns

return self.session.post(
                request_url, data=data, files=files, json=json).json()

when POSTing a new document to /v1/projects/<id>/docs. The document is created correctly (201) but the .json() throws a JSONDecodeError as the content of the response is empty, i.e. there is simply nothing to parse

@Hironsan should the API return a content from the post request /v1/projects/<id>/docs ? Or should this be fixed in the doccano client ?

MaxHoefl avatar Oct 17 '20 16:10 MaxHoefl

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.72. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Nov 27 '20 10:11 issue-label-bot[bot]

Hi,

I have a similar issu when trying to upload a txt file using :

doccano_client.post_doc_upload(1,'txt','input_1.txt','./')

And it returns :

simplejson.errors.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

Any update about this bug ?

Best regards,

SwannChelly avatar May 11 '21 08:05 SwannChelly

Hi, i also have a similar issue while using post_doc_upload(), the file is correctly uploaded but it seems to crash when i try to injest it.

Following the error raised by doccano task:

[2021-06-22 13:59:58,940: INFO/MainProcess] Task api.tasks.injest_data[14eabc0b-c104-40e8-ac23-3f068f872e8b] received
[2021-06-22 13:59:58,946: ERROR/ForkPoolWorker-2] Task api.tasks.injest_data[14eabc0b-c104-40e8-ac23-3f068f872e8b] raised unexpected: Http404('No Project matches the given query.')
Traceback (most recent call last):
  File "/Users/enzo/Workspace/Testing/doccano-ft/dft_env/lib/python3.9/site-packages/django/shortcuts.py", line 76, in get_object_or_404
    return queryset.get(*args, **kwargs)
  File "/Users/enzo/Workspace/Testing/doccano-ft/dft_env/lib/python3.9/site-packages/django/db/models/query.py", line 435, in get
    raise self.model.DoesNotExist(
api.models.Project.DoesNotExist: Project matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/enzo/Workspace/Testing/doccano-ft/dft_env/lib/python3.9/site-packages/celery/app/trace.py", line 450, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/Users/enzo/Workspace/Testing/doccano-ft/dft_env/lib/python3.9/site-packages/celery/app/trace.py", line 731, in __protected_call__
    return self.run(*args, **kwargs)
  File "/Users/enzo/Workspace/Testing/doccano-ft/dft_env/lib/python3.9/site-packages/backend/api/tasks.py", line 90, in injest_data
    project = get_object_or_404(Project, pk=project_id)
  File "/Users/enzo/Workspace/Testing/doccano-ft/dft_env/lib/python3.9/site-packages/django/shortcuts.py", line 78, in get_object_or_404
    raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
django.http.response.Http404: No Project matches the given query.

EnzoNclt avatar Jun 22 '21 14:06 EnzoNclt

Hi, same issue here

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/doccano_api_client/init.py in post_doc_upload(self, project_id, file_name, file_path, column_data, column_label, delimiter, encoding, format) 678 delimiter=delimiter, 679 encoding=encoding, --> 680 format=format, 681 ) 682

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/doccano_api_client/init.py in post_doc_upload_binary(self, project_id, files, column_data, column_label, delimiter, encoding, format) 643 "uploadIds": upload_ids, 644 } --> 645 return self.post(f"v1/projects/{project_id}/upload", json=upload_data) ... 398 elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf': 399 idx += 3 --> 400 return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting value: line 2 column 1 (char 1) news_test.json.zip

@Hironsan mitekudasai

When I debug the code, found the error message is

'\n<!doctype html>\n<html lang="en">\n<head>\n <title>Server Error (500)</title>\n</head>\n<body>\n <h1>Server Error (500)</h1><p></p>\n</body>\n</html>\n'

cliuxinxin avatar Jul 15 '22 01:07 cliuxinxin