简体   繁体   中英

How to make Asynchronous http request using python grequests

I am not able to get the asynchronous property out of this code. The calling url has a sleep of 10 seconds.

The grequests.send command finishes immediately but I am not getting the request at the server.

If I am using r.send() or grequests.map(), the request getting blocked for 10 seconds which I do not expect.

import grequests
url = 'http://localhost:9000/test'
r = grequests.post(url)
grequests.send(r, grequests.Pool(1))

Please Help. Thanks.

It sounds like it could be that port 9000 is blocked (eg, through UFW or iptables). If you are using Windows, I would open Fiddler and try again. If you are using Linux, I'd install nmap.

nmap -p 9000 localhost

A result of "filtered" means that the port is blocked. A result of "closed" or "open" means the port is not blocked.

In your Python code, you may want to have brackets [] around the URL with single quotes. You may also want to replace "url" with "urls".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM