Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sssss55578693
pytest_allure
提交
fa77327d
P
pytest_allure
项目概览
sssss55578693
/
pytest_allure
通知
7
Star
1
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pytest_allure
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fa77327d
编写于
9月 21, 2021
作者:
J
jiafeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 2 function in Requests.py
上级
83fcb89f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
105 addition
and
0 deletion
+105
-0
Common/Request.py
Common/Request.py
+105
-0
未找到文件。
Common/Request.py
浏览文件 @
fa77327d
...
...
@@ -120,6 +120,111 @@ class Request:
else
:
return
response_dicts
def
post_request_multipart
(
self
,
url
,
data
,
header
,
file_parm
,
file
,
f_type
):
"""
提交Multipart/form-data 格式的Post请求
:param url:
:param data:
:param header:
:param file_parm:
:param file:
:param type:
:return:
"""
if
not
url
.
startswith
(
'http://'
):
url
=
'%s%s'
%
(
'http://'
,
url
)
print
(
url
)
try
:
if
data
is
None
:
response
=
requests
.
post
(
url
=
url
,
headers
=
header
)
else
:
data
[
file_parm
]
=
os
.
path
.
basename
(
file
),
open
(
file
,
'rb'
),
f_type
enc
=
MultipartEncoder
(
fields
=
data
,
boundary
=
'--------------'
+
str
(
random
.
randint
(
1e28
,
1e29
-
1
))
)
header
[
'Content-Type'
]
=
enc
.
content_type
response
=
requests
.
post
(
url
=
url
,
params
=
data
,
headers
=
header
)
except
requests
.
RequestException
as
e
:
print
(
'%s%s'
%
(
'RequestException url: '
,
url
))
print
(
e
)
return
()
except
Exception
as
e
:
print
(
'%s%s'
%
(
'Exception url: '
,
url
))
print
(
e
)
return
()
# time_consuming为响应时间,单位为毫秒
time_consuming
=
response
.
elapsed
.
microseconds
/
1000
# time_total为响应时间,单位为秒
time_total
=
response
.
elapsed
.
total_seconds
()
Common
.
Consts
.
STRESS_LIST
.
append
(
time_consuming
)
response_dicts
=
dict
()
response_dicts
[
'code'
]
=
response
.
status_code
try
:
response_dicts
[
'body'
]
=
response
.
json
()
except
Exception
as
e
:
print
(
e
)
response_dicts
[
'body'
]
=
''
response_dicts
[
'text'
]
=
response
.
text
response_dicts
[
'time_consuming'
]
=
time_consuming
response_dicts
[
'time_total'
]
=
time_total
return
response_dicts
def
put_request
(
self
,
url
,
data
,
header
):
"""
Put请求
:param url:
:param data:
:param header:
:return:
"""
if
not
url
.
startswith
(
'http://'
):
url
=
'%s%s'
%
(
'http://'
,
url
)
print
(
url
)
try
:
if
data
is
None
:
response
=
requests
.
put
(
url
=
url
,
headers
=
header
)
else
:
response
=
requests
.
put
(
url
=
url
,
params
=
data
,
headers
=
header
)
except
requests
.
RequestException
as
e
:
print
(
'%s%s'
%
(
'RequestException url: '
,
url
))
print
(
e
)
return
()
except
Exception
as
e
:
print
(
'%s%s'
%
(
'Exception url: '
,
url
))
print
(
e
)
return
()
time_consuming
=
response
.
elapsed
.
microseconds
/
1000
time_total
=
response
.
elapsed
.
total_seconds
()
Common
.
Consts
.
STRESS_LIST
.
append
(
time_consuming
)
response_dicts
=
dict
()
response_dicts
[
'code'
]
=
response
.
status_code
try
:
response_dicts
[
'body'
]
=
response
.
json
()
except
Exception
as
e
:
print
(
e
)
response_dicts
[
'body'
]
=
''
response_dicts
[
'text'
]
=
response
.
text
response_dicts
[
'time_consuming'
]
=
time_consuming
response_dicts
[
'time_total'
]
=
time_total
return
response_dicts
if
__name__
==
'__main__'
:
url
=
'http://c-api-sellerbasicservice.staging.shopeemobile.com/api/fulfillment/order/get_forder_from_oms'
header
=
{
'shop-id'
:
'321239'
,
'region-id'
:
'SG'
,
'user-id'
:
'321238'
,
'Content-Type'
:
'application/json'
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录