1

I have met some 502 error and how can I make a client robust against 5XX errors by retrying the request once or twice if you receive one, that way even if they do occur, your software will continue running normally.

My codes are here http://pastebin.com/YHpZQ9Z9

4

1 回答 1

2

您需要执行以下操作:

try:
    # code that can potentially throw a 502
except HTTPError as e:
    if e.code == 502:
        #put your retry logic here
    else
        print 'Failure: ' + str(e.reason)

有关更多信息,请阅读urllib2.HTTPError文档

于 2013-08-07T02:07:50.687 回答