I am trying to use Mayan API to upload the zip file which contains shape files to create map points. I am using document_upload_create API with Python requests to upload the document and passing the file as argument. When trying to upload the file, it is throwing an error :
{“detail”:“JSON parse error - ‘utf-8’ codec can’t decode byte 0xff in position 234: invalid start byte”}
My API looks like this:
import requests
import json
import sys
import mimetypes
url = “http://10.12.23.2/api/v4/documents/upload/”
DocumentTYPEID = sys.argv[1]
PATH = sys.argv[2]
FILENAME = sys.argv[3]
CONTENTTYPE = mimetypes.MimeTypes().guess_type(FILENAME)[0]
FILE_CONTENT = open(PATH+‘/’+FILENAME,‘rb’)
payload = {‘document_type_id’: DocumentTYPEID}
files=[
(‘file’,(FILENAME,FILE_CONTENT,CONTENTTYPE))
]
headers = {
‘Content-Type’: ‘application/json’,
‘Accept’: ‘application/json’,
‘Authorization’: ‘Basic YawdadadaW46wawdad0AyMDIz’
}
response = requests.request(“POST”, url, headers=headers, data=payload, files=files)
print(response.text)
Please suggest something that help me either to convert the encoding of the file or tell me if we can upload zip file or not.