【问题标题】:How to send multiple http requests python如何发送多个http请求python
【发布时间】:2014-09-02 22:06:12
【问题描述】:

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

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

【问题讨论】:

  • 您可以使用for loop
  • 一比一是什么意思?不止一个顺序?在平行下?重用参数,什么?
  • @MartijnPieters 啊!抱歉,我现在编辑了问题,谢谢
  • @AnishShah 好的,那么我如何接收每个请求的响应?我的意思是循环会等到我收到每个单独请求的响应吗?
  • @bitgeeky 你可以追加到一个列表..

标签: python python-2.7 request python-requests grequests


【解决方案1】:

您应该查看使用requests 和gevent 的grequests

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]>]

【讨论】:

    猜你喜欢
    • 2022-07-26
    • 1970-01-01
    • 2013-03-23
    • 2015-12-26
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多