Python:捕获基于RESTAPI的DMS服务上传后文档的输出
我正在尝试通过RESTAPI将文件上传到DMS。每次我将文件上传到DMS时,都会生成一个唯一的doc_id,需要保存在DB中 我正在为第一部分即上传尝试以下代码Python:捕获基于RESTAPI的DMS服务上传后文档的输出,python,Python,我正在尝试通过RESTAPI将文件上传到DMS。每次我将文件上传到DMS时,都会生成一个唯一的doc_id,需要保存在DB中 我正在为第一部分即上传尝试以下代码 def upload_sotr(filepath:str,file_name:str): upload_url = 'dms_url_path' f = open(os.path.join(filepath,file_name),'rb') files = {"file":(os.path.j
def upload_sotr(filepath:str,file_name:str):
upload_url = 'dms_url_path'
f = open(os.path.join(filepath,file_name),'rb')
files = {"file":(os.path.join(filepath,file_name),f)}
resp = requests.post(url=url,files=files)
if resp.status_code==201:
print('Success!!')
##Want to get the doc_id as shown below and return the same
return 'Success!!'
else:
strg='Failure'
return strg
但是,我无法从上传文档后的upload\u url
中捕获文档id字符串。通常,doc_id作为
{
doc_type: 'image',
doc_id: 'AAD3456Q77'
}
正如代码中所指出的,我应该做什么样的技巧来发布
print('Success!!')
以便获得文档id?好的,我找到了技巧
我应该用
data = resp.json()
doc_id = data['doc_id''
return doc_id
因此,完整的代码是:
def upload_sotr(filepath:str,file_name:str):
upload_url = 'dms_url_path'
f = open(os.path.join(filepath,file_name),'rb')
files = {"file":(os.path.join(filepath,file_name),f)}
resp = requests.post(url=url,files=files)
if resp.status_code==201:
data = resp.json()
doc_id = data['doc_id']
return doc_id
else:
strg='Failure'
return strg