python - python 如何发送多个http请求

标签 python python-2.7 request python-requests grequests

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

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

最佳答案

您应该查看grequests它使用 requests和 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]>]

关于python - python 如何发送多个http请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24711993/

相关文章:

python - 如何比较 Pandas Python 2.7 中给定 DataFrame 中的两个单元格

javascript - Node 在类异步方法中设置 this.var

ios - Swift Alamofire 请求错误 - 调用中的额外参数

python - 如何在Pycharm中将现有目录转换为python包

javascript - 使用 Node.js 执行 Python 脚本

python - 值错误 : unsupported pickle protocol: 4 with pandas

c - MPI有超时机制吗?

python - 如何在 RedHat 上安装 numpy 和 matplotlib?

python - 从多个文件中搜索和排序数据

python - _tkinter.TclError : bitmap "pyimage2" not defined