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

  • SEARCH
  • Home
  • 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 6784779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:02:26+00:00 2026-05-26T17:02:26+00:00

The function urllib2.urlopen freezes. So my question is simple: Why does urlopen freeze my

  • 0

The function urllib2.urlopen freezes. So my question is simple:

  • Why does urlopen freeze my script for ever even though timeout is set?
  • How can I access data at an URL (in this case: http://api.own3d.tv/live?channel=FnaticTV) without the possibility of my Python process freezing up for all eternity?

This is the part where is freezes (In own3d.py):

# Try three times to make contact
while True:
    try:
        # Connect to API 

        # Right here! It freezes here
        connection = urllib2.urlopen(request, timeout=10)

        xmlstring = connection.read() 
    except URLError as e:
        tries += 1
        if tries >= 3:
            sys.stderr.write(
                      'own3dStreamsUpdater: Fatal error: Repeated timeouts')
            exit()

This is the stack trace after my KeyboardInterrupt

Traceback (most recent call last):
  File "", line 1, in 
  File "honsapp/own3dStreamsUpdater.py", line 53, in updateStreamInfo
    streamInfo = getStreamInfo(stream)
  File "honsapp/own3d.py", line 98, in getStreamInfo
    connection = urllib2.urlopen(request, timeout=10)
  File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 394, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 412, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1199, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/local/lib/python2.7/urllib2.py", line 1170, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/local/lib/python2.7/httplib.py", line 1027, in getresponse
    response.begin()
  File "/usr/local/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline()
  File "/usr/local/lib/python2.7/socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
KeyboardInterrupt

Edit

I let my script run over night. I don’t know exactly how long it took (Though more than five minutes) but the script finally gave up and gave me a stacktrace:

Traceback (most recent call last):
  File "honsapp/own3dStreamsUpdater.py", line 260, in 
    newInfo()
  File "honsapp/own3dStreamsUpdater.py", line 172, in newInfo
    result = updateStreamInfo(stream)
  File "honsapp/own3dStreamsUpdater.py", line 53, in updateStreamInfo
    streamInfo = getStreamInfo(stream)
  File "/root/Dropbox/Projects/honstreams/honsapp/own3d.py", line 98, in getStreamInfo
    connection = urllib2.urlopen(request, timeout=10)
  File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 394, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 412, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1199, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/local/lib/python2.7/urllib2.py", line 1170, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/local/lib/python2.7/httplib.py", line 1027, in getresponse
    response.begin()
  File "/usr/local/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python2.7/httplib.py", line 371, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine: ''
  • 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-26T17:02:27+00:00Added an answer on May 26, 2026 at 5:02 pm

    This script doesn’t freeze at all, but it’s a brilliant example of why you shouldn’t code while tired. The loop that’s supposed to try to connect to the API three times will continue for ever, because I forgot to put a break in there.

    This question was so stupid I wouldn’t blame you for removing it.

    Fixed code:

    # Try three times to make contact
    while True:
        try:
            # Connect to API 
            connection = urllib2.urlopen(request, timeout=10)
            xmlstring = connection.read()
            break
        except URLError as e:
            tries += 1
            if tries >= 3:
                sys.stderr.write(
                          'own3dStreamsUpdater: Fatal error: Repeated timeouts')
                exit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using urllib2 's urlopen function to try and get a JSON result from
In my application I am using the urllib2.urlopen() function to call an api and
So I have the following lines of code in a function sock = urllib.urlopen(url)
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _
Iam trying to follow the multithreading example given in: Python urllib2.urlopen() is slow, need
Are there any equivalents in objective-c to the following python urllib2 functions? Request, urlopen,
I open urls with: site = urllib2.urlopen('http://google.com') And what I want to do is
There is a backend function in my site that will call urllib.urlopen(url)) to retrieve
For a personal research/fun project I am using the Python urllib2() function. However, when
My project makes various calls to external API's using Python's urllib2.urlopen . I'm using

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.