Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

119. add retry for python requests #119

Open
ly525 opened this issue Jul 20, 2018 · 0 comments
Open

119. add retry for python requests #119

ly525 opened this issue Jul 20, 2018 · 0 comments

Comments

@ly525
Copy link
Owner

ly525 commented Jul 20, 2018

import requests

def handle_response(response): 
       #do something with response

def do_request():
    url = 'https://www.google.com'
    retry_count = 3

    for i in range(retry_count):
        try:
             req = requests.get(url, timeout = 60)
    	     if req.status_code not in (200, 201):
        	     raise Exception('bad status :%d' % req.status_code)
    	     handle_response(req)
             break
    	except Exception as e:
             print('retry_count: %s, url:%s' % (i + 1, url))
    	     pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant