这个python异常是什么意思

时间:2014-10-23 14:46:36

标签: python httpurlconnection

当我尝试点击我的主页时,有时会看到以下异常。

ERROR:root:HTTPConnectionPool(host='0.0.0.0', port=8003): Max retries exceeded with url:  
/snapshot/?app=cdnstats&key=28736ba5fbe151d5ff6678015c8f6ade (Caused by <class 'socket.error'>:  
[Errno 61] Connection refused)
Traceback (most recent call last):
File "/Users/rokumar/CDNStats/cdnstats/app/core/views.py", line 257, in get_snapshot_data
data = templates.render_snapshot(controllers.get_snapshot_data())
File "/Users/rokumar/CDNStats/cdnstats/util.py", line 260, in decorated
expiry, mem_args, func, args, kwargs)
File "/Users/rokumar/CDNStats/cdnstats/util.py", line 227, in get_data_from_meminstance
data = func(*args, **kwargs)
File "/Users/rokumar/CDNStats/cdnstats/app/core/controllers.py", line 255, in get_snapshot_data
return util.call_get_api(config.CDNSTATS_API_URL + 'snapshot/?', data)
File "/Users/rokumar/CDNStats/cdnstats/util.py", line 123, in call_get_api
raise ex

以下是生成异常的代码段。

def call_get_api(url, data):
try:
    data = data.copy()
    data['key'] = request.args.get('key')
    data['app'] = config.APPNAME

    query = soft_urlencode(data)
    response = requests.get(url + query)
    if response.status_code == 200:
        return response.json()
    else:
        apiexception = APIException(response.content)
        apiexception.status_code = response.status_code
        raise apiexception
except UnicodeEncodeError as ex:
    print ex
    raise ex

except Exception as ex:
    raise ex

我间歇地看到异常并且我的应用程序严重减速。我不明白这个例外或出了什么问题。例外情况表示超出了最大重试次数,但我没有任何重试逻辑。

1 个答案:

答案 0 :(得分:0)

在urlopen中,尝试设置retries=Falseretries=1。默认值为3,因此可能是您的重试逻辑。