grequets和requests案例各一个,使用上对比:

import grequests
import requests headers = {
"content-type": "application/json;charset=UTF-8",
"authentication": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
".eyJpc3MiOiJwYXNzcG9ydHRlc3Quc2VuZ3VvLm1lIiwiZXhwIjoxNjA5MjI4MzczLCJwYXNzcG9ydF9pZCI6MzI4OTg4MCwic3ViIjoiYXV0aF90b2tlbiIsImF1ZCI6ImxpbmdzaG91IiwiaWF0IjoxNjA4NjIzNTczfQ.UiKxI2gtDy9vl43F_i4305KaGeADAyuTpJxSwtXqAfY",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/72.0.3626.121 Safari/ "
}
url = 'https://cashiertest.sg.me/api/finance/getonedayshopprofit'
data = '{"date": "2020-12-22"}' def g_request():
res = [grequests.post(url=url, data=data, headers=headers)]
rp = grequests.map(res)
for i in rp:
print(i.text) def requests_():
res = requests.post(url=url, data=data, headers=headers)
print(res.text) if __name__ == '__main__':
g_request()
requests_() 控制台输出都一样:
{"message":"请求成功","data":{"shop_profit":{"is_confirmed":false,"gross_profit":null,"gross_profit_rate":null},"shop_goods_profits":[]}}
{"message":"请求成功","data":{"shop_profit":{"is_confirmed":false,"gross_profit":null,"gross_profit_rate":null},"shop_goods_profits":[]}}

grequest标准使用:

import grequests  # gevent+request

request_list = [
grequests.get('https://www.runoob.com/python3/python3-file-methods.html', timeout=0.1),
grequests.get('https://www.zxgj.cn/g/tupiancaijian'),
grequests.get('https://www.json.cn/')
]
# 响应列表
response_list = grequests.map(request_list)
# 取响应码(和request用于)
response_content = response_list[0].status_code
# 取json
# ips = [ret.json() for ret in response_list if ret and ret.status_code == 200]
print(response_content)

最新文章

  1. ASP.NET MVC Html.BeginForm 设置 timeout
  2. $Host.Runspace.ThreadOptions = “ReuseThread”有神马用?
  3. nios II--实验4——按键中断软件部分
  4. Python中判断是否为闰年,求输入日期是该年第几天
  5. Delphi中的变量作用域简介
  6. paypal IPN 接口返回INVALID参数可能问题
  7. CDC
  8. HDU2176尼姆博弈
  9. 字符编解码的故事(ASCII,ANSI,Unicode,Utf-8)
  10. hdoj 2544 最短路【dijkstra or spfa】
  11. 【转】Android HAL实例解析
  12. 【Chromium中文文档】Chrome/Chromium沙箱 - 安全架构设计
  13. IIS的安装
  14. 利用 onload 事件监控跨站资源
  15. [LeetCode66]Plus One
  16. Redis入门到高可用(四)—— Redis的五种数据结构的内部编码
  17. 【原创】Qt 使用ODBC driver 连接SQL Server
  18. idea中maven依赖不能下载的解决办法
  19. Spring AOP详解(转载)
  20. dip,px,sp区别及使用场景

热门文章

  1. <一>继承的基本意义
  2. flutter系列之:在flutter中使用流式布局
  3. js-day04-作业
  4. C++四舍五入并且保留7为小数
  5. 如何通过C#合并Word文档?
  6. python中的字符串(1)
  7. SQLMap入门——判断是否存在注入
  8. 90%的Java开发人员都会犯的5个错误
  9. Hello 2023 A-D
  10. SSM框架——MyBatis