Typesense JSON Decoding Issues
TLDR Philip faced issues with JSON decoding errors when redeploying typesense. Jason suggested checking the Typesense logs and trying with curl, providing ways to diagnose the issue. Philip planned to investigate further.

Sep 30, 2022 (12 months ago)
Philip
01:57 PMPhilip
01:59 PMimport json
import os
import sys
import typesense
curr_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(1, os.path.abspath(os.path.join(curr_dir, os.pardir)))
client = typesense.Client({
'api_key': {key},
'nodes': [{
'host': {host},
'port': '443',
'protocol': 'https'
}],
'connection_timeout_seconds': 2
})
# Drop pre-existing collection if any
try:
client.collections['books'].delete()
except Exception as e:
pass
# Create a collection
create_response = client.collections.create({
"name": "books",
"fields": [
{"name": "title", "type": "string"},
{"name": "authors", "type": "string[]", "facet": True},
{"name": "publication_year", "type": "int32", "facet": True},
{"name": "ratings_count", "type": "int32"},
{"name": "average_rating", "type": "float"},
{"name": "image_url", "type": "string"}
],
"default_sorting_field": "ratings_count"
})
print(create_response)
Output:
Traceback (most recent call last):
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 29, in <module>
create_response = client.collections.create({
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/site-packages/typesense/collections.py", line 18, in create
return (Collections.RESOURCE_PATH, schema)
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/site-packages/typesense/api_call.py", line 141, in post
return self.make_request(, endpoint, as_json,
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/site-packages/typesense/api_call.py", line 127, in make_request
raise last_exception
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/site-packages/typesense/api_call.py", line 111, in make_request
error_message = r.json().get('message', 'API error.')
File "/Users/philipjohnson/.asdf/installs/python/3.8.13/lib/python3.8/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Jason
03:46 PMPhilip
03:49 PMPhilip
03:49 PMJason
03:50 PMPhilip
03:51 PM
Typesense
Indexed 2764 threads (79% resolved)
Similar Threads
Solving Typesense Cloud Interface Issue in Python
Orion had an issue querying from Python in the Typesense Cloud interface. Kishore Nallan identified the problem within the array declaration. They then discussed improving error messages and Orion offered to make a PR.



Issues with Importing Typesense Collection to Different Server
Kevin had problems migrating a Typesense collection between Docusaurus sites on different machines. Jason advised them on JSONL format, handling server hosting, and creating a collection schema before importing documents, leading to successful import.



Discussing a Bug with Go Client in Typesense Server
adil reports a bug with the Go client in Typesense Server. Jason acknowledges the bug, takes note of adil's suggestion for decoding, deferring further actions to a third party.