doccano-client
doccano-client copied to clipboard
Cannot Injest Data with the API
How to reproduce the behaviour
Hi, i have an issue when i try to use post_doc_upload_binary(). Here is a snippet from my code:
from doccano_api_client import DoccanoClient
# instantiate a client and log in to a Doccano instance
doccano_client = DoccanoClient(
'http://localhost:8000',
'admin',
'password'
)
# get basic information about the authorized user
r_me = doccano_client.get_me()
api_token = doccano_client._login("admin", "password")
# print the details from the above query
print(api_token)
with open('annotation_guide.md', 'r') as file:
guideline = file.read()
project = doccano_client.create_project("Integration Doccano", "This is a test",
project_type="SequenceLabeling", guideline=guideline, randomize_document_order=False, collaborative_annotation=True)
print(doccano_client.get_project_list())
file_path = "./some_path"
label_path = "./label_config.json"
files = os.listdir(file_path)
doccano_client.post_doc_upload_binary(project['id'], files, format="plain")
It returns me this error:
[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.
It seems to works pretty fine without the API, directly via doccano frontend page, but fail through the API
Your Environment
- Operating System:
- Python Version: 3.9.5
- Package Version: 1.0.2
Seems to be an error the function documentation, format="plain" as an argument of post_doc_upload does not exist, worked for me with format="TextFile"