Update apiMethod.py
This commit is contained in:
parent
badda99595
commit
b102a0fc46
|
@ -22,17 +22,17 @@ def post(headers, address, mime_type, timeout=10, data=None, files=None, cookies
|
||||||
:param mime_type: 请求参数格式(form_data,raw)
|
:param mime_type: 请求参数格式(form_data,raw)
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间
|
||||||
:param data: 请求参数
|
:param data: 请求参数
|
||||||
:param files: 文件路径
|
:param files: 上传文件请求参数(dict)
|
||||||
:param cookies:
|
:param cookies:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# 判断请求参数类型
|
# 判断请求参数类型
|
||||||
if 'form_data' in mime_type:
|
if 'form_data' in mime_type:
|
||||||
for i in files:
|
for key in files:
|
||||||
value = files[i]
|
value = files[key]
|
||||||
|
# 判定参数值是否为文件,如果是则替换为二进制值
|
||||||
if '/' in value:
|
if '/' in value:
|
||||||
file_parm = i
|
files[key] = (os.path.basename(value), open(value, 'rb'))
|
||||||
files[file_parm] = (os.path.basename(value), open(value, 'rb'))
|
|
||||||
enc = MultipartEncoder(
|
enc = MultipartEncoder(
|
||||||
fields=files,
|
fields=files,
|
||||||
boundary='--------------' + str(random.randint(1e28, 1e29-1))
|
boundary='--------------' + str(random.randint(1e28, 1e29-1))
|
||||||
|
|
Loading…
Reference in New Issue