Python GET请求导致100%CPU使用率高峰

时间:2014-12-04 17:12:32

标签: python http get python-requests

我使用python请求库(版本2.4.1)来执行简单的get请求,代码如下,没有什么花哨的。在大多数网站上都没有问题。但在某些网站上,特别是www.pricegrabber.com,我体验到100%的CPU使用率,代码永远不会超过get请求。没有超时,没有,只是一个永远不会停止的巨大的CPU使用率峰值。

import requests
url = 'http://www.pricegrabber.com'
r = requests.get(url, timeout=(1, 1))
print 'SUCESS'
print r

1 个答案:

答案 0 :(得分:4)

使用python 2.7,'的最新稳定版本请求'库,并以[{3}}启用日志记录表示HTTP请求卡在重定向循环中。

  

INFO:requests.packages.urllib3.connectionpool:启动新的HTTP连接(1):www.pricegrabber.com
  DEBUG:requests.packages.urllib3.connectionpool:" GET / HTTP / 1.1" 301 20
  DEBUG:requests.packages.urllib3.connectionpool:" GET /index.php/ut=43bb2597a77557f5 HTTP / 1.1" 301 20
  DEBUG:requests.packages.urllib3.connectionpool:" GET /?ut = 43bb2597a77557f5 HTTP / 1.1" 301 20
  DEBUG:requests.packages.urllib3.connectionpool:" GET /?ut = 43bb2597a77557f5 HTTP / 1.1" 301 20
  DEBUG:requests.packages.urllib3.connectionpool:" GET /?ut = 43bb2597a77557f5 HTTP / 1.1" 301 20

     

...

这一直持续到:

  

requests.exceptions.TooManyRedirects:超过30个重定向。

我以前用来发现这个的代码:

#!/usr/bin/env python

import logging
import requests

logging.basicConfig(level=logging.DEBUG)

url = 'http://www.pricegrabber.com'
r = requests.get(url, timeout=(1, 1))

print 'SUCCESS'
print r
相关问题