Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User lancew's Avatar
    Join Date
    Mar 2004
    Posts
    14
    Hi everyone,
    I have been trying to use urllib and am encountering problems. I have tried uninstalling Python and reinstalling and still it fails.
    Below is the code that fails, I have other actual useful code that I want to use this for, but to simplify fault-finding I wrote this short bit of code and it failed too.



    import urllib
    print "hello"
    f = urllib.urlopen("http://www.python.org").read()
    print f

    ----
    The output and errors I see are below:


    hello
    Traceback (most recent call last):
    File "ped.py", line 908, in run_click
    File "E:\Python\Urllib.py.py", line 3, in ?
    f = urllib.urlopen("http://www.python.org").read()
    File "c:\resource\urllib.py", line 43, in urlopen
    return _urlopener.open(url)
    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')


    ---

    Any assistance would be really appreciated.

    Lance

  2. #2
    Super Contributor JOM's Avatar
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976
    Quote Originally Posted by lancew View Post
    Traceback (most recent call last):
    File "ped.py", line 908, in run_click
    Try whether it runs outside Ped. I had a small script which failed inside Ped and spent the whole evening trying to debug a perfectly ok script - in vain, naturally

    Summary:
    save as a file and run it from PythonShell.

    Cheers,

    --jouni

  3. #3
    Nokia Developer Moderator croozeus's Avatar
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,635
    Hi lancew,

    Nothing is wrong with your code

    Jouni is right! There are instances when trying to run scripts on PED fails, especially with scripts related to Access points and Upload data scripts, it usually returns the error below.

    (0, 'getaddrinfo failed')
    However the same script will run perfectly fine on the PythonScript Shell.

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  4. #4
    Registered User lancew's Avatar
    Join Date
    Mar 2004
    Posts
    14
    Thanks for the re-assurance.
    I tried it not using PED and it worked ok.

    However... my original code that is talking to a web API (JSON) still dies.


    I shall do appropriate screengrabs etc and post them here.
    It works to my base url www.lancewicks.com but then it fails when reading into my NoseRub install. www.lancewicks.com/noserub/ and deeper.

    Thanks for the input.

    Lance

  5. #5
    Registered User lancew's Avatar
    Join Date
    Mar 2004
    Posts
    14
    Hmmm.... interesting.
    I just ran the code I posted and it ran okay.
    I edited the URL to my API url and it worked ok.

    I then added import JSON and tried to read "f" using Json and it died.
    When it dies it brings up the slect AP dialog twice. It only does it once when it works. Weird.

    No unable to run at all. I am rebooting my phone to see if that helps.

    Lance

  6. #6
    Registered User hyon's Avatar
    Join Date
    Jan 2008
    Posts
    22
    I have a similar problem, but with Ensymble. My code works fine in Python Script Shell, but when I package it into a sis file, it stops at the following line:

    onlineFile = urllib.urlopen(URL + Filename")

    It doesn't even try to connect to the web (there is an icon that shows up normally, when it tries to connect). Is there some extra procedure that I missed? I use Jurgen Scheible's default access point setter code. Maybe that's causing some trouble?

    Any help is appreciated!

    Best,
    Hyon Lee

  7. #7
    Registered User hyon's Avatar
    Join Date
    Jan 2008
    Posts
    22
    Just to add some details to my previous post:

    I'm using a 3rd Ed machine (Nokia 5500) and using Ensymble v0.26.
    The program closes when it gets to the aforementioned line of code.

  8. #8
    Nokia Developer Champion gaba88's Avatar
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,688
    Quote Originally Posted by hyon View Post
    I have a similar problem, but with Ensymble. My code works fine in Python Script Shell, but when I package it into a sis file, it stops at the following line:

    onlineFile = urllib.urlopen(URL + Filename")

    It doesn't even try to connect to the web (there is an icon that shows up normally, when it tries to connect). Is there some extra procedure that I missed? I use Jurgen Scheible's default access point setter code. Maybe that's causing some trouble?
    hi hyon
    it will be better if you tell the dibo about the procedure you followed to make your sis file.

  9. #9
    Nokia Developer Moderator croozeus's Avatar
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,635
    Quote Originally Posted by hyon View Post

    onlineFile = urllib.urlopen(URL + Filename")

    You have a problem in the code.
    For extracting data from HTML documents using urllib, it goes like this

    For eg.
    Code:
    sock = urllib.urlopen("http://diveintopython.org/"
    You might need to modify your code to

    onlineFile = urllib.urlopen(URL + "Filename")

    Or try having the whole string in one variable and then try like

    Code:
    URL= URL + "Filename"
    onlineFile = urllib.urlopen(URL)
    Hope that helps

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  10. #10
    Registered User hyon's Avatar
    Join Date
    Jan 2008
    Posts
    22
    The following is a test script that I wrote solely to test the urllib.urlopen command in a sis file:

    Code:
    import appuifw
    import urllib
    import os
    import e32
    
    file = urllib.urlopen(u"http://www.mobilenin.com/pys60/resources/ex_upload_file_to_url.py")
    fileContent = file.read()
    file.close()
    
    newFile = open(u"e:\\path.py", 'w')
    newFile.write(fileContent)
    newFile.close()
    and the following is how I packaged it using Ensymble v0.27:

    Code:
    ensymble.py py2sis --autostart --runinstall downloadTest.py
    Also, I used Symbian Open Signed to sign it.

    Please tell me what I am doing wrong!

    Thanks,
    Hyon

  11. #11
    Nokia Developer Moderator bogdan.galiceanu's Avatar
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471
    Quote Originally Posted by hyon View Post
    and the following is how I packaged it using Ensymble v0.27:

    Code:
    ensymble.py py2sis --autostart --runinstall downloadTest.py
    Also, I used Symbian Open Signed to sign it.

    Please tell me what I am doing wrong!

    Thanks,
    Hyon
    You have to specify the capabilities when creating the sis file with Ensymble. So it should be like:
    Code:
    ensymble.py py2sis  --caps=LocalServices+NetworkServices+ProtServ+ReadUserData+SwEvent+UserEnvironment+WriteUserData+ReadDeviceData+WriteDeviceData --autostart --runinstall downloadTest.py

  12. #12
    Registered User hyon's Avatar
    Join Date
    Jan 2008
    Posts
    22
    ah ha! it works now.

    although, it is VERY redundant, since i specify those capabilities on symbian signed...

    thank you all for your help!

    Hyon

Similar Threads

  1. which phones for laptop
    By dvdljns in forum PC Suite API and PC Connectivity SDK
    Replies: 2
    Last Post: 2006-02-14, 12:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved