OmniDocs
, I am able to Add Document
using Postman, passing it as form-data.python
it is returning Bad request
.<NGOAddDocumentBDO>
<cabinetName>samplecabinet</cabinetName>
<folderIndex>3185</folderIndex>
<documentName>Restweb postman</documentName>
<userDBId></userDBId>
<volumeId>1</volumeId>
<accessType>S</accessType>
<createdByAppName>txt</createdByAppName>
<enableLog>Y</enableLog>
<versionFlag>N</versionFlag>
<textAlsoFlag></textAlsoFlag>
<ownerType>U</ownerType>
<ownerIndex>2</ownerIndex>
<nameLength></nameLength>
<thumbNailFlag>N</thumbNailFlag>
<imageData></imageData>
<encrFlag>N</encrFlag>
<passAlgoType>MD5</passAlgoType>
<userName>test123</userName>
<userPassword>Test@1234</userPassword>
<comment></comment>
<locale>en_US</locale>
<NGOAddDocDataDefCriterionBDO>
<dataDefIndex>22</dataDefIndex>
<dataDefName>DIGI2</dataDefName>
<NGOAddDocDataDefCriteriaDataBDO>
<indexId>43</indexId>
<indexType>I</indexType>
<indexValue>123</indexValue>
</NGOAddDocDataDefCriteriaDataBDO>
</NGOAddDocDataDefCriterionBDO>
<NGOAddDocKeywordsCriterionBDO>
<keyword></keyword>
</NGOAddDocKeywordsCriterionBDO>
</NGOAddDocumentBDO>
'content-type': 'multipart/form-data'
, but not able to determine where the request is going wrong, if it is working fine with postman, not able to figure out the problem in fast-api. lstr_add_document_response = "Empty"
lxml_add_document = """
<NGOAddDocumentBDO>
<cabinetName>samplecabinet</cabinetName>
<folderIndex>3185</folderIndex>
<documentName>Restweb postman</documentName>
<userDBId></userDBId>
<volumeId>1</volumeId>
<accessType>S</accessType>
<createdByAppName>txt</createdByAppName>
<enableLog>Y</enableLog>
<versionFlag>N</versionFlag>
<textAlsoFlag></textAlsoFlag>
<ownerType>U</ownerType>
<ownerIndex>2</ownerIndex>
<nameLength></nameLength>
<thumbNailFlag>N</thumbNailFlag>
<imageData></imageData>
<encrFlag>N</encrFlag>
<passAlgoType>MD5</passAlgoType>
<userName>test123</userName>
<userPassword>Test@1234</userPassword>
<comment></comment>
<locale>en_US</locale>
<NGOAddDocDataDefCriterionBDO>
<dataDefIndex>22</dataDefIndex>
<dataDefName>DIGI2</dataDefName>
<NGOAddDocDataDefCriteriaDataBDO>
<indexId>43</indexId>
<indexType>I</indexType>
<indexValue>123</indexValue>
</NGOAddDocDataDefCriteriaDataBDO>
</NGOAddDocDataDefCriterionBDO>
<NGOAddDocKeywordsCriterionBDO>
<keyword></keyword>
</NGOAddDocKeywordsCriterionBDO>
</NGOAddDocumentBDO>
"""
lstr_headers = {'content-type': 'multipart/form-data'}
lstr_data = {'NGOAddDocumentBDO': lxml_add_document, 'file': open('/home/donny/Desktop/omnidocs/output-document/8VQUI_something.pdf', "wb+")}
try:
lstr_add_document_response = requests.post(gstr_omnidocs_add_document_service,
data=lstr_data,
headers=lstr_headers)
print(gstr_omnidocs_add_document_service)
print(lstr_data)
print(lstr_headers)
except Exception as e:
logger.error(str(e), exc_info=True)
print("Response text=", lstr_add_document_response.text.encode('utf8'))
print(lstr_add_document_response.content)
# replace < with <
new_lstr_add_document_response = (lstr_add_document_response.text).replace("<", "<")
# get the response from the add document response
lstr_soup_response = BeautifulSoup(new_lstr_add_document_response, features="xml")
return lstr_soup_response
except Exception as e:
logger.error(str(e), exc_info=True)
Postman
on right side should have icon </>
to open function Code snippet
which can generate code for different languages - even for Python
(requests
and http.client
)
It gives me code which sends file in files=...
import requests
url = "http://10.10.2.41:8003/OmniBook"
payload={'NGOAddDocumentBDO': '<XML>'}
files=[
('file',('file',open('/path/to/file','rb'),'application/octet-stream'))
]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
But I couldn't test it.