#community-help

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.

Powered by Struct AI
+11
Sep 30, 2022 (12 months ago)
Philip
Photo of md5-d5f18904df8d699f2661b5860c0abe71
Philip
01:57 PM
hey all, have been successfully running typesense for a 1+ years, but deciding to redeploy somewhere else and getting really strange JSON decoding errors while reusing my old code or even the python sample code - any idea what's going on? details in thread...
01:59
Philip
01:59 PM
Code:
import 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
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:46 PM
Hmm, could you try this with curl to see if you can replicate the issue? Could you also check the Typesense logs for any errors?
Philip
Photo of md5-d5f18904df8d699f2661b5860c0abe71
Philip
03:49 PM
Yeah so nothing in the logs, but was the first time trying docker-compose, didn’t use docker compose the second time and now working. ¯\_(ツ)_/¯
03:49
Philip
03:49 PM
Health checks worked though so not sure what the issue was
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:50 PM
Essentially, we want to know the exact output from the Typesense API before we JSON decode it in the Python library… This way we can see if it’s an issue with the python library or Typesense
Philip
Photo of md5-d5f18904df8d699f2661b5860c0abe71
Philip
03:51 PM
Got it, I’m going to try to get it running again when I have a bit more time and will let you know if I discover anything. Thanks Jason!
+11