Asynchronous Requests with Python requests

前端 未结 12 1453
予麋鹿
予麋鹿 2020-11-22 08:47

I tried the sample provided within the documentation of the requests library for python.

With async.map(rs), I get the response codes, but I want to get

12条回答
  •  无人共我
    2020-11-22 09:05

    async is now an independent module : grequests.

    See here : https://github.com/kennethreitz/grequests

    And there: Ideal method for sending multiple HTTP requests over Python?

    installation:

    $ pip install grequests
    

    usage:

    build a stack:

    import grequests
    
    urls = [
        'http://www.heroku.com',
        'http://tablib.org',
        'http://httpbin.org',
        'http://python-requests.org',
        'http://kennethreitz.com'
    ]
    
    rs = (grequests.get(u) for u in urls)
    

    send the stack

    grequests.map(rs)
    

    result looks like

    [, , , , ]
    

    grequests don't seem to set a limitation for concurrent requests, ie when multiple requests are sent to the same server.

提交回复
热议问题