Giter VIP home page Giter VIP logo

python_uwazi_api's Introduction

Python Uwazi API


Quick Start

To use the API install the requirements

pip3 install -r requirements.txt

and use it like this:

uwazi_adapter = UwaziAdapter(user='admin', password='admin', url='http://localhost:3000')
uwazi_adapter.entities.get_one(shared_id='shared_id', language='en')
uwazi_adapter.files.get_document(shared_id='shared_id', language='en')
uwazi_adapter.settings.get()
uwazi_adapter.templates.get()
uwazi_adapter.thesauris.get()

API

Entities

get_one(shared_id: str, language: str)
get_id(shared_id: str, language: str)
get_shared_ids(to_process_template: str, batch_size: int, unpublished: bool = True)
get(template_id: str, batch_size: int, language: str = 'en', published: bool = False)
get_by_id(entity_id: str)
upload(entity: Dict[str, any], language: str)
delete(share_id:str)

Files

get_document(shared_id: str, language: str)
get_document_by_file_name(file_name: str)
save_document_to_path(shared_id: str, languages: List[str], path: str)
upload_file(pdf_file_path, share_id, language, title)
upload_image(image_binary, title, entity_shared_id, language)
delete_file(id)

Settings

get()
get_languages()

Templates

set(language, template)
get()

Thesauris

get(language: str)
add_value(thesauri_name, thesauri_id, thesauri_values, language)

python_uwazi_api's People

Contributors

gabriel-piles avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

python_uwazi_api's Issues

uploading an entity with a select and multi-select attribute

whenever I try to pass a string as the value for a select or multi-select field, I get an error reading:
Error uploading entity 422 {"error":"validation failed","validations":[{"keyword":"metadataMatchesTemplateProperties","schemaPath":"#/metadataMatchesTemplateProperties","params":{"keyword":"metadataMatchesTemplateProperties"},"dataPath":".metadata['source']","message":"related dictionary value/s does not exists"

However, I checked the dictionary for the field, and the value I was trying to upload was present in the dictionary.

For reference, I was trying to upload an entity of the type "Media Articles"
The field in question was "Source"
I was trying to upload a "Source" value of "Free Tibet", which is present in the source dictionary according to the "Thesauri" section

This is how I'm creating the entity:

entity = {'title': row['title_final'],
               'template': template_id,
               'metadata': {
                            'article_contents': [{'value': row['article_final']}],
                            'date_published': [{'value': row['date']}],
                            'date_scrapped': [{'value': row['date_accessed']}],
                            'source': [{'value': 'Free Tibet'}], # gives error
                            'link': [{'value': row['url']}],
               }
        }

If I comment out the "Source" field, the upload is successful.

Any advice would be greatly appreciated. Thanks

@natasha-todi
@pddocs

error upload: maximum field length

When trying to upload an article, I get the following error:

Error uploading entity 422 
{"error":"validation failed",
"validations":
[{"keyword":"metadataMatchesTemplateProperties",
"schemaPath":"#/metadataMatchesTemplateProperties",
"params":{"keyword":"metadataMatchesTemplateProperties"},
"dataPath":".metadata['article_contents']",
"message":"maximum field length exceeded"}],
"prettyMessage":"validation failed",
"requestId":8694} 

{'title': 'Farewell Letters: A Tribute to the Civil Society Groups, Bloggers, and Media Outlets We Lost in 2021', 
'template': '5d7fa0edabfb862c766385b3', 
'metadata': {...}

It appears that the article text is too long. I have two questions related to this issue:

  1. Is there any way around this?
  2. What is the maximum field length for Uwazi?

Thanks

@natasha-todi
@pddocs

Error trying to connect to Uwazi with UwaziAdapter()

Recently, my code started raising an error when I try to connect to Uwazi with UwaziAdapter().

As far as I know, nothing in my code was changed between the time when it was functional and when it started failing.

Also, my uwazi credentials have not been changed.

The error is as follows:

Traceback (most recent call last):
  File "post_articles.py", line 307, in <module>
    uploadToUwazi(user, password, template_id, url, df)
  File "post_articles.py", line 143, in uploadToUwazi
    uwazi_adapter = UwaziAdapter(user=user, password=password, url=url)
  File "/Users/Tanner1/Desktop/Projects/RightsActionLab/uwazi/uwazi_api/UwaziAdapter.py", line 14, in __init__
    self.uwazi_request = UwaziRequest(url, user, password)
  File "/Users/Tanner1/Desktop/Projects/RightsActionLab/uwazi/uwazi_api/UwaziRequest.py", line 16, in __init__
    self.connect_sid = self.get_connect_sid()
  File "/Users/Tanner1/Desktop/Projects/RightsActionLab/uwazi/uwazi_api/UwaziRequest.py", line 24, in get_connect_sid
    return response.cookies['connect.sid']
  File "/Users/Tanner1/miniconda3/lib/python3.7/site-packages/requests/cookies.py", line 328, in __getitem__
    return self._find_no_duplicates(name)
  File "/Users/Tanner1/miniconda3/lib/python3.7/site-packages/requests/cookies.py", line 399, in _find_no_duplicates
    raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='connect.sid', domain=None, path=None"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "post_articles.py", line 314, in <module>
    raise Exception(error)
Exception: "name='connect.sid', domain=None, path=None"

The only cause I can think of might have something to do with 2-factor authentication. I first noticed the issue right after I set up 2-factor auth on my account

Any help is greatly appreciated.

Thanks!

@natasha-todi
@pddocs

Installation error

when I try to install the repo with:
python3 -m pip install git+https://github.com/huridocs/python_uwazi_API.git

I get the following error:
ERROR: git+https://github.com/huridocs/python_uwazi_API.git does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

Trying another method, when I try first cloning the repo:
git clone https://github.com/huridocs/python_uwazi_API.git

installing the requirements:
cd python_uwazi_API/ && pip3 install -r ./requirements.txt

and installing the library:
pip3 install -e .

I get a similar error:
ERROR: file:///Users/Tanner1/Desktop/Projects/RightsActionLab/uwazi_project/python_uwazi_API does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

If someone could please advise on how to proceed it would be greatly appreciated. Thanks!

posting a template entity

I've managed to establish a connection to our server, but I cannot figure out how to post an entity.

I want to post a basic entity to a template called 'test'

The template consists of a title string, a text-body string, and a date. How do I achieve this?

Thanks

@natasha-todi
@pddocs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.