【发布时间】:2016-11-07 23:34:23
【问题描述】:
我正在使用Python requestsget方法查询MediaWiki API,但是收到响应需要很多时间。相同的请求通过 Web 浏览器非常快地收到响应。我在请求 google.com 时遇到了同样的问题。以下是我在 Windows 10 上的 Python 3.5 中尝试的示例代码:
response = requests.get("https://www.google.com")
response = requests.get("https://en.wikipedia.org/wiki/Main_Page")
response = requests.get("http://en.wikipedia.org/w/api.php?", params={'action':'query', 'format':'json', 'titles':'Labor_mobility'})
但是,我在检索其他网站时不会遇到这个问题,例如:
response = requests.get("http://www.stackoverflow.com")
response = requests.get("https://www.python.org/")
【问题讨论】:
-
回复需要多长时间?
-
Python 请求也不正式支持 python 3.5
-
您是否尝试在网址后添加
stream=True?例如:requests.get("https://www.google.com", stream=True) -
@NendoTaka,感谢您的回复。通常它们需要不到 0.5 秒,但是对于我现在面临的问题,它们每个都需要大约 22 秒!另外,我尝试了 Python 2.7,但我遇到了同样的问题。我也试过 requests.get("google.com", stream=True)。它没有改变任何东西。
-
同样的问题,对我有用:unix.stackexchange.com/questions/500286/…
标签: python performance get python-requests python-3.5