×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Jan 2007
    Posts
    80

    problems with urllib

    Hi I have the N95 with the latest version of python but I keep getting problems with urllib, here is the output

    Error 1
    >>> import urllib
    >>> a = urllib.urlretrieve("http://www.google.com")
    Traceback (most recent call last):
    File "<console>", line 1, in ?
    File "c:\resource\urllib.py", line 50, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
    File "c:\resource\urllib.py", line 150, in retrieve
    fp = self.open(url, data)
    File "c:\resource\urllib.py", line 123, in open
    return getattr(self, name)(url)
    File "c:\resource\urllib.py", line 229, in open_http
    h.endheaders()
    File "c:\resource\httplib.py", line 454, in endheaders
    self._send_output()
    File "c:\resource\httplib.py", line 405, in _send_output
    self.send(msg)
    File "c:\resource\httplib.py", line 385, in send
    self.connect()
    File "c:\resource\httplib.py", line 355, in connect
    socket.SOCK_STREAM):
    File "c:\resource\socket.py", line 229, in getaddrinfo
    r_host = gethostbyname(host)
    IOError: [Errno socket error] (0, 'getaddrinfo failed')
    >>>
    -------------------------------------------------------------


    Error 2
    -------------------------------------------------
    a = urllib.urlretrieve("http://www.google.com")
    Traceback (most recent call last):
    File "<console>", line 1, in ?
    File "c:\resource\urllib.py", line 50, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
    File "c:\resource\urllib.py", line 153, in retrieve
    import tempfile
    File "c:\resource\site.py", line 112, in platsec_import
    raise ImportError("No module named "+name)
    ImportError: No module named tempfile

  2. #2
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: problems with urllib

    Hello federico2929

    When I try the following code it works perfect on my device and it ask me to select the access point as I am trying to retrive a Url.

    Code:
    >>>import urllib
    >>>a = urllib.urlretrieve("http://www.google.com")
    No problems with the code.Have you installed python correctly?
    Refer here http://croozeus.googlepages.com/installation

    Hope that helps

    Best Regards
    croozeus
    Pankaj Nathani
    www.croozeus.com

  3. #3
    Super Contributor
    Join Date
    May 2006
    Location
    Oulu, Finland
    Posts
    622

    Re: problems with urllib

    Hey federico2929,

    I confirm the problem! On my N95 (with a selfsigned version) I get the Error 2 directly trying to retrieve http://www.google.com from the interactive shell.

    As a remark, it asks me __twice__ to select the access point.

    If you have an emulator (I do not have all the tools with me), does it behave the same way? Is there the tempfile module anywhere?.

    It looks like there's an error during the imports in urllib that would cascade the second error??

    But I cannot go deeper than suggestions at the moment.

    LFD
    Devices:
    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:
    http://www.lfdm.net/thesis

  4. #4
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: problems with urllib

    Quote Originally Posted by lfd View Post
    On my N95 (with a selfsigned version) I get the Error 2 directly trying to retrieve http://www.google.com from the interactive shell.
    Perhaps you should try to call urlretrieve with filename-parameter:
    Code:
    filename = u"D:\\temp.html"
    urlretrieve(url, filename)
    Quote Originally Posted by lfd View Post
    - - it asks me __twice__ to select the access point.
    Perhaps urlretrieve first tries to resolve the IP-address of www.google.com (from domain name server) and then fetch the url?

    Error 1 ("IOError: [Errno socket error] (0, 'getaddrinfo failed')") may occur if Python script shell does not have Network-capability (or something).

  5. #5
    Regular Contributor
    Join Date
    Jan 2007
    Posts
    80

    Re: problems with urllib

    Tried your solution but it didn't work

    Here is the output:

    >>> filename = u"D:\\temp.html"
    >>>
    >>> urllib.urlretrieve("www.google.com",filename)
    Traceback (most recent call last):
    File "<console>", line 1, in ?
    File "c:\resource\urllib.py", line 50, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
    File "c:\resource\urllib.py", line 150, in retrieve
    fp = self.open(url, data)
    File "c:\resource\urllib.py", line 123, in open
    return getattr(self, name)(url)
    File "c:\resource\urllib.py", line 333, in open_file
    return self.open_local_file(url)
    File "c:\resource\urllib.py", line 336, in open_local_file
    import mimetypes, mimetools, rfc822, StringIO
    File "c:\resource\site.py", line 112, in platsec_import
    raise ImportError("No module named "+name)
    ImportError: No module named mimetypes
    >>>

  6. #6
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: problems with urllib

    Quote Originally Posted by federico2929 View Post
    >>> urllib.urlretrieve("www.google.com",filename)
    You forgot the protocol prefix (http://), which was in the original example.

    In many cases it is useful to try the code example first in the python console in a desktop computer. There you can eliminate most common python specific errors before trying in the phone.

  7. #7
    Regular Contributor
    Join Date
    Jan 2007
    Posts
    80

    Re: problems with urllib

    Quote Originally Posted by aaaaapo View Post
    You forgot the protocol prefix (http://), which was in the original example.

    In many cases it is useful to try the code example first in the python console in a desktop computer. There you can eliminate most common python specific errors before trying in the phone.

    Yeah I also tried that and nothing ...

    >>> import urllib
    >>> a = urllib.urlretrieve("http://www.google.com")
    Traceback (most recent call last):
    File "<console>", line 1, in ?
    File "c:\resource\urllib.py", line 50, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
    File "c:\resource\urllib.py", line 153, in retrieve
    import tempfile
    File "c:\resource\site.py", line 112, in platsec_import
    raise ImportError("No module named "+name)
    ImportError: No module named tempfile


    But the version with the data file did work

    a = urllib.urlretrieve("http://www.google.com","e:\tempfile.html")
    Last edited by federico2929; 2007-11-07 at 00:29.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    24

    Re: problems with urllib

    Hello! I´ve the same problem, and I have it in my emulator, too. When I put:
    -------------------------------
    import urllib
    page = urllib.urlopen("http://www.polarfitnesstrainer.com").read()
    print page
    -------------------------------
    I become several errors in Send, connect... and so on and finally I get an IOError: Errno Socket Error.

    Does anyone know anything about this problem?

    Thank you!

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Re: problems with urllib

    getaddrinfo failed means, that the hostname could not be resolved in DNS. This can be due to one of the following:

    • no internet connection.
    • dns server not available.
    • dns server has no or outdated records for the queried hostname.

  10. #10
    Nokia Developer Champion
    Join Date
    Sep 2007
    Location
    Bhavnagar
    Posts
    928

    Re: problems with urllib

    Hi,
    i am using the same script that is given in mobile python book. In this url has been retrieve and destination file has been created but am nt able to display it . The code which i am using is
    Code:
    import urllib,appuifw,e32
    u="http://www.python.org/images/python-logo.gif"
    d=u"e://allpy//python-logo.gif"
    
    urllib.urlretrieve(u,d)
    lock=e32.Ao_lock()
    v=appuifw.Content_handler(lock.signal)
    v.open(d)
    lock.wait()
    
     Output is..
    
    Traceback (most recent call last):
      File "ped.py", line 1366, in run_click
      File "D:\Ped.temp\Urltry.py", line 8, in ?
        v.open(d)
    SymbianError: [Errno -28] KErrBadName
    >>>
    how can i display it?
    Jajal Mehul

Similar Threads

  1. Several problems with NMIT 4.1 MMS
    By jtalviva in forum General Messaging
    Replies: 0
    Last Post: 2006-03-10, 11:03
  2. Several problems with NMIT 4.1
    By jtalviva in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-03-10, 10:59
  3. Problems with Nokia carkit CK-1W
    By Batunas in forum General Development Questions
    Replies: 1
    Last Post: 2004-02-09, 18:18
  4. general problems in 3410
    By fredgauchet in forum Mobile Java General
    Replies: 1
    Last Post: 2002-08-26, 14:38

Posting Permissions

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