I have spacy object of type <class 'spacy.tokens.doc.Doc'>
import spacy
import requests
nlp = spacy.load("en_core_web_sm")
spacy_doc = nlp("hello")
How can I send this object as payload in a api request? Currently when I try to post it using below code
requests.post(API_URL, json={'doc': spacy_doc}, timeout=3)
I am getting the below error
ERROR:Object of type 'Doc' is not JSON serializable
Doc.to_bytes() is mentioned in https://spacy.io/usage/saving-loading
but when I use it
requests.post(API_URL, json={'doc': spacy_doc.to_bytes()}, timeout=3)
I get
ERROR:Object of type 'bytes' is not JSON serializable
What is the correct way to send spacy doc and reconstruct it back in the api(I am developing this target api service and its made using fastapi)?