Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:13:31+00:00 2026-05-30T10:13:31+00:00

When urllib2.request reaches timeout, a urllib2.URLError exception is raised. What is the pythonic way

  • 0

When urllib2.request reaches timeout, a urllib2.URLError exception is raised.
What is the pythonic way to retry establishing a connection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:13:32+00:00Added an answer on May 30, 2026 at 10:13 am

    I would use a retry decorator. There are other ones out there, but this one works pretty well. Here’s how you can use it:

    @retry(urllib2.URLError, tries=4, delay=3, backoff=2)
    def urlopen_with_retry():
        return urllib2.urlopen("http://example.com")
    

    This will retry the function if URLError is raised. Check the link above for documentation on the parameters, but basically it will retry a maximum of 4 times, with an exponential backoff delay doubling each time, e.g. 3 seconds, 6 seconds, 12 seconds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A urllib2 request receives binary response as below: 00 00 00 01 00 04
this is the script >> import ClientForm import urllib2 request = urllib2.Request(http://ritaj.birzeit.edu) response =
What should data look like before data encoding in: urllib2.Request(someurl,data) I tried [('name1','value1'),('name2','value2'),...] but
How can I make a keep alive HTTP request using Python's urllib2?
Python's urllib2 follows 3xx redirects to get the final content. Is there a way
Here's my code: import urllib2.request response = urllib2.urlopen(http://www.google.com) html = response.read() print(html) Any help?
With this code, urllib2 make a GET request: #!/usr/bin/python import urllib2 req = urllib2.Request('http://www.google.fr')
class FourSquareTestHandler(SecurePageHandler): def get(self): logging.info('***********************') logging.info('*****GET****') logging.info('***********************') try: request =\ urllib2.Request('https://api.foursquare.com/v2/users/self/checkins?oauth_token=LAF1W3VMSI0DGQYIBTNIYVIZG4VE2RFGESM45LDJRSQHFTK3&v=20120123') data = simplejson.load(urllib2.urlopen(request))
So I adapted urllib2 as suggested by answers to another question : class HttpRequest(urllib2.Request):
theurl = 'http://bit.ly/6IcCtf/' urlReq = urllib2.Request(theurl) urlReq.add_header('User-Agent',random.choice(agents)) urlResponse = urllib2.urlopen(urlReq) htmlSource = urlResponse.read() if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.