Results 1 to 4 of 4

Thread: urlopen error

  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Default urlopen error

    Hi,

    I'm having a hard time figuring out what is wrong with this piece of code :

    Code:
    <?xml version="1.0"?>
    <window type="window" id="14000">
    	<defaultcontrol always="false">100</defaultcontrol>
    	<onload lang="python"><![CDATA[
    from BeautifulSoup import BeautifulSoup, SoupStrainer
    import re
    import urllib2
    
    BASE_URL = "http://www.some-url.com"
    
    contents = []
    
    # Get the soup to work with.
    response = urllib2.urlopen( BASE_URL )
    soup = response.read()
    response.close
    
    ...
    I'm always having that error:

    NOTICE: <urlopen error (61, 'Connection refused')>



    Any clue?

  2. #2
    Join Date
    Feb 2010
    Posts
    4

    Default Solve

    Hi all,

    It seems the server I was trying to reach did'nt like the 'default http proxy of Boxee'.
    I'm not 100% sure about that but still, here is the code I used to solve the problem :

    Code:
    from BeautifulSoup import BeautifulSoup, SoupStrainer
    import urllib2
    
    BASE_URL = "http://some-url.com"
    	
    # "Bypass" BOXEE proxy (if not we'll have error 61, 'connection refused')
    proxy_support = urllib2.ProxyHandler({})
    opener = urllib2.build_opener(proxy_support)
    urllib2.install_opener(opener)
    	
    # Fake user-agent to make sure the server let us in
    user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"
    headers = { "User-Agent" : user_agent }
    	
    # Build a request
    request = urllib2.Request( BASE_URL, {}, headers )
    	
    # Try to reach the server
    try:
    	response = urllib2.urlopen(request)
    except IOError, e:
    	if hasattr(e, 'reason'):
    		print 'We failed to reach a server.'
    		print 'Reason: ', e.reason
    	elif hasattr(e, 'code'):
    		print 'The server couldn\'t fulfill the request.'
    		print 'Error code: ', e.code
    		
    		return None
    
    # Everything went well
    print response.read()
    response.close
    Voilą !

    http://www.voidspace.org.uk/python/a....shtml#proxies

  3. #3
    Join Date
    Feb 2009
    Posts
    427

    Default

    I think for boxee apps you can use the Http class
    http://developer.boxee.tv/Http_Class

  4. #4

    Default

    Don't use urllib, use the Boxee API's Http class. It'll make your life easier and you won't have to code so many error checks. Plus utilizing the Http class automatically dumps any cookies being set by a remote server into Boxee's cookie jar.
    Last edited by DPK; February 20th, 2010 at 03:15 PM.
    Common issues w/ Boxee:
    Beta Important Info | FAQ & Support Requests | Hulu Mature Content | Search

    UnBoxeed app development:
    Comics.com | ESPN360 | Weather

    For more info, follow app development on Twitter!

Similar Threads

  1. MLB.TV Returned the following error: an unknown error
    By mlb fan in forum boxee for appletv help
    Replies: 3
    Last Post: July 7th, 2010, 05:04 AM
  2. Unable to create patchstick, keep getting error 404 or error 8
    By jadenman1 in forum boxee for appletv help
    Replies: 0
    Last Post: February 1st, 2010, 11:26 AM
  3. Error:6
    By pkeenan in forum boxee for mac help
    Replies: 7
    Last Post: January 6th, 2009, 07:19 PM
  4. Error 10?
    By whitef in forum boxee for appletv help
    Replies: 2
    Last Post: December 30th, 2008, 03:34 PM
  5. Replies: 2
    Last Post: November 25th, 2008, 11:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •