alexb
1
Hi, I am trying to upload a PDF that is 1.5mb and getting the above error. What am I doing wrong?
This is my python script:
import requests
session = requests.Session()
url = “https://api.vectara.io/v1/upload?c=CUSTOMER_ID&o=1”
payload={}
files=[
(‘file’,(‘file’,open(‘/Users/path/to/file’,‘rb’),‘application/octet-stream’))
]
headers = {
‘Content-Type’: ‘multipart/form-data’,
‘Accept’: ‘application/json’,
‘x-api-key’: ‘API_KEY’
}
response = session.post(url, headers=headers, data=payload, files=files)
print(response.text)
session.close()
Thanks for your question. The following works fine. Can you please try it?
import requests
session = requests.Session()
files={
"file": ("i1040gi.pdf", open("~/data/i1040gi.pdf", "rb"), "application/octet-stream")
}
post_headers = {
"x-api-key": API_KEY
}
response = session.post(
url = f"https://api.vectara.io/v1/upload?c={CUSTOMER_ID}&o={CORPUS_ID}",
headers=post_headers,
files=files)
print(response.text)
session.close()
alexb
3
Thank you! Yes, this worked.
Looks like the headers weren’t necessary. Fwiw, the code I used was copied from the API Playground.
shane
4
Thank you for the feedback @alexb ! I’ll look at why the API Playground is producing that and see if I can get it fixed