#community-help

Issues Importing Data to TypeSense Python Client

TLDR Mehdi was having trouble importing data to a TypeSense Python client. Kishore Nallan released a new Python client version to fix Mehdi's encoding issues.

Powered by Struct AI
8
29mo
Solved
Join the chat
Jun 30, 2021 (29 months ago)
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
01:32 PM
Hello everyone
I'm new to TypeSense
I have a Python client and I'm trying to import data to it using this code:

with open(jsonl_path, encoding='utf-8') as jsonl_file:
    client.collections[name].documents.import_(jsonl_file.read(), {'action': 'create'})

It's returning:

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 3340888-3340891: Body ('تونس') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

When I do jsonl_file.read().encode('utf-8') it returns TypeError: Object of type bytes is not JSON serializable

How can I solve this?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:34 PM
You are using Python 3, right? Can you post a short github gist containing a sample file and the corresponding python code snippet using the import? That way I can reproduce and suggest.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:59 PM
Thanks, taking a look
02:22
Kishore Nallan
02:22 PM
Mehdi This requires an update to the Python client. I will publish it shortly so that you can test
02:29
Kishore Nallan
02:29 PM
Mehdi I just published 0.12.0 version of the Python client: can you please try using that? You still have to do .encode('utf-8') but it will work now.
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
02:58 PM
Yes thank you ! 💯
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:44 PM
👍