gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:50 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com