Python: How to make multiple HTTP POST queries in one moment?

孤者浪人 提交于 2019-12-24 11:05:05

问题


How to make multiple HTTP POST queries in one moment using Python?

Using an external library with an example can be a good solution.


回答1:


External lib? Maybe an internal one would do the trick...

http://docs.python.org/library/httplib.html#examples

specifically:

params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})

If you wanted to process multiple HTTP POST queries (asynchronous) you could cycle through them in a loop, opening subprocesses using subprocess.Popen. Although a better solution would probably be asyncore. This site has an example of using asyncore for http requests (like POST).




回答2:


You should consider using threading (or maybe multiprocessing, but here the GIL is not a problem) to enable concurrent execution.



来源:https://stackoverflow.com/questions/2261035/python-how-to-make-multiple-http-post-queries-in-one-moment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!