如何发送多个http请求python [英] How to send multiple http requests python

查看:73
本文介绍了如何发送多个http请求python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python request.post() 将数据发送到远程数据库.我应该如何使用 python 使用不同的数据在同一 URL 上发送多个请求(大约 20-30 个)?

I am using python request.post() to send data to a remote database. How should I send more than one request(around 20-30) on same URL using different data using python ?

此外,对于这种情况,顺序是否可以正常工作,还是我需要并行发出请求?

Also, will sequential work fine for this case or do I need to make the requests in parallel ?

推荐答案

你应该看看 grequests使用 requests 和 gevent

You should look at grequests which uses requests and gevent

import grequests

urls = [
    'http://www.heroku.com',
    'http://python-tablib.org',
    'http://httpbin.org',
    'http://python-requests.org',
    'http://kennethreitz.com'
]

rs = (grequests.get(u) for u in urls)
grequests.map(rs)
[<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]

这篇关于如何发送多个http请求python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆