Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User cawhitworth's Avatar
    Join Date
    Mar 2004
    Posts
    3
    Hi;

    I'm getting errors when using urllib2 on my N95 with v1.9.0 - urllib works fine:

    Code:
    >>> import urllib
    >>> file = urllib.urlopen("http://news.bbc.co.uk/")
    >>> file.close()
    but urllib2 always gives me errors:

    Code:
    >>> import urllib2
    >>> file = urllib2.urlopen("http://news.bbc.co.uk/")
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "c:\resource\python25\urllib2.py", line 121, in urlopen
        return _opener.open(url, data)
      File "c:\resource\python25\urllib2.py", line 374, in open
        response = self._open(req, data)
      File "c:\resource\python25\urllib2.py", line 392, in _open
        '_open', req)
      File "c:\resource\python25\urllib2.py", line 353, in _call_chain
        result = func(*args)
      File "c:\resource\python25\urllib2.py", line 1100, in http_open
        return self.do_open(httplib.HTTPConnection, req)
      File "c:\resource\python25\urllib2.py", line 1089, in do_open
        fp = socket._fileobject(r, close=True)
    TypeError: __init__() got an unexpected keyword argument 'close'
    >>>
    I can probably rework my code to use urllib, but as I want to use http auth, it's a pain having to write the headers by hand and urllib2 makes life a lot easier :-/

    Does this look familiar/expected/unexpected to anyone?

  2. #2
    Registered User mikezs's Avatar
    Join Date
    Sep 2008
    Posts
    36
    I'm getting exactly the same error on my E71.

  3. #3
    Regular Contributor ashwinurao's Avatar
    Join Date
    Oct 2007
    Posts
    114
    The problem is that there are 2 socket modules now. One provided by us giving socket functionalities on the phone and another by Python core giving basic socket APIs. In 1.4.x the socket module was a superset over the original socket provided by Python. In 1.9.0 we have kept the original socket module and PyS60 1.4.x socket module separate.

    The urllib module refers to APIs from the Python socket module and since you have packaged your application in PyS60 1.4.x compatibility mode these APIs have different arguments.

    Solution: Package your script by un-checking the 'Prioritize PyS60 module library' checkbox. If you want to use some socket APIs only provided by us, for eg: select_access_point() you can do "import btsocket; btsocket.select_access_point()" and use this new name wherever needed.
    import antigravity

  4. #4
    Registered User mikezs's Avatar
    Join Date
    Sep 2008
    Posts
    36
    In the python 2.5 manual it states that the function takes the same parameters, and returns a file like object:
    Code:
    urllib2.urlopen(url[, data][, timeout])
    The additional close parameter is in the python source code, not user code.

    Is this a bug with the python runtime then?

  5. #5
    Registered User cawhitworth's Avatar
    Join Date
    Mar 2004
    Posts
    3
    Quote Originally Posted by ashwinurao View Post
    The problem is that there are 2 socket modules now. One provided by us giving socket functionalities on the phone and another by Python core giving basic socket APIs. In 1.4.x the socket module was a superset over the original socket provided by Python. In 1.9.0 we have kept the original socket module and PyS60 1.4.x socket module separate.

    The urllib module refers to APIs from the Python socket module and since you have packaged your application in PyS60 1.4.x compatibility mode these APIs have different arguments.

    Solution: Package your script by un-checking the 'Prioritize PyS60 module library' checkbox. If you want to use some socket APIs only provided by us, for eg: select_access_point() you can do "import btsocket; btsocket.select_access_point()" and use this new name wherever needed.
    I'm not quite sure what you're driving at. My logs above are direct C&Ps from a bluetooth console on the phone, there's no packaging of anything going on whatsoever. I get the same results if I enter the code directly into a shell on the phone, or if I drop a script onto the phone and execute it from the shell - unless the shell itself is packaged in 1.4.x compatibility mode.

    For what it's worth, the error appears after a succesful connection to the network has been made - and if I put a non-existent hostname in the url, I get an "getaddrinfo failed", so name resolution seems to be happening fine too.
    Last edited by cawhitworth; 2009-01-07 at 17:56.

  6. #6
    Regular Contributor ashwinurao's Avatar
    Join Date
    Oct 2007
    Posts
    114
    Quote Originally Posted by cawhitworth View Post
    *snip*

    - unless the shell itself is packaged in 1.4.x compatibility mode.

    *snip*
    Exactly!

    We create scriptshell in PyS60 mode which is why you see this problem in bluetooth console. You can however create scriptshell in pycore mode easily:

    - Download pys60-1.9.0_src.zip
    - Navigate to ext\amaretto\scriptshell and copy the default.py script
    - Use PyS60 application packager(part of PythonForS60_1.9.0_Setup.exe) and package this script into a sis file(Remember to de-select 'Prioritize PyS60 library'). Also set Heap size to 1M,16M.
    - Voila! This is nothing but ScriptShell.

    We will think of something so that users will not face such a problem in the future.
    import antigravity

  7. #7
    Nokia Developer Champion marcelobarrosalmeida's Avatar
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    752
    I had the same problem with socket library. My detailed steps for building the new shell is here (thanks for PyS60 guys !)

    1) Copied ext\amaretto\scriptshell\default.py from
    https://garage.maemo.org/frs/downloa...-1.9.0_src.zip
    into some directory, for instance pyshell\

    2) Copied emsymble.py from
    https://garage.maemo.org/frs/downloa...onForS60_1.9.0
    .tar.gz
    into pyshell

    3) Copied dir templates from
    https://garage.maemo.org/frs/downloa...onForS60_1.9.0
    .tar.gz
    into pyshell

    4) Created and ran the following buildsis.bat file for generating
    the sis:

    -----------------------------------
    @echo off

    SET VERSION=1.9.0
    SET PYTHON=C:\Python25\python
    SET APPNAME=PyShell
    SET CAPBLS=LocalServices+NetworkServices+ReadUserData+WriteUserDa
    ta+UserEnvironment


    %PYTHON% .\ensymble.py py2sis --mode=pycore --uid=0xefefef00
    --version="%VERSION%" --appname="%APPNAME%"
    --caps="%CAPBLS%" default.py
    "%APPNAME%%VERSION%.sis"

    ------------------------------------------

    5) Removed the Python shell 1.9.0 and installed the previous
    one.

    I didn't know which UID to use, so I put one in the free range.

    Ref: https://garage.maemo.org/tracker/ind...=854&atid=3201

Similar Threads

  1. Replies: 2
    Last Post: 2008-10-17, 19:23
  2. Wikipedia article on PyS60
    By shubhendra in forum Python
    Replies: 15
    Last Post: 2008-08-12, 17:59
  3. Pys60 Talks #1 : Vote for the time !
    By croozeus in forum Python
    Replies: 5
    Last Post: 2008-07-15, 09:09
  4. [Announce] Home to Pys60 Developers - croozeus.com
    By bogdan.galiceanu in forum Python
    Replies: 8
    Last Post: 2008-07-12, 19:31
  5. Replies: 0
    Last Post: 2006-03-06, 11:56

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