On Mon, Jul 05, 2010 at 01:30:48PM -0400, Ross Vandegrift wrote:
> Looks like Debian recently changed the system python to python2.6, so
> I'm taking this chance to update my app to make sure there aren't any
> issues.
> 
> When I hit a page via "paster serve ..." I get a weird exception from
> imports in WebError.  Has anyone seen this?

No.

> I can't be the first
> person to try to run on python2.6!

I'm running my Pylons app on python2.6 with no problems.

> I tried rolling back to WebError
> 0.10.1 (which I was using without issue on python2.5), but it didn't
> help.
...
> Exception happened during processing of request from ('127.0.0.1', 39433)
> Traceback (most recent call last):
...
>   File 
> "/usr/local/lib/python2.6/dist-packages/WebError-0.10.2-py2.6.egg/weberror/formatter.py",
>  line 295, in quote
>     s = s.encode('latin1', 'htmlentityreplace')
>   File "/usr/lib/python2.6/encodings/__init__.py", line 100, in 
> search_function
>     level=0)
> TypeError: import_module() got an unexpected keyword argument 'level'

Well, it's not WebError's fault.  unicode.encode() is a basic Python feature
that appears to be broken in your setup.

encodings/__init.py around line 100 looks like this:

            # Import is absolute to prevent the possibly malicious import of a
            # module with side-effects that is not in the 'encodings' package.
            mod = __import__('encodings.' + modname, fromlist=_import_tail,
                             level=0)

Maybe there's something wrong with your system Python?  Can you try to
reproduce with

    $ python2.6
    >>> __import__('encodings.latin_1', fromlist=['*'], level=0)
    <module 'encodings.latin_1' from '/usr/lib/python2.6/encodings/latin_1.pyc'>

If that works fine (and I expect it will), then maybe some packages in
your project is trying to hook into Python's import machinery (e.g. by
overriding __builtin__.__import__), but hasn't updated the API to be
compatible with Python 2.6.

Can you get a Paster shell and check if __import__ is still the builtin
function, or if something has replaced it?

    >>> __import__
    <built-in function __import__>

(It would be even better to do that in a pdb session after the actual
crash.)

Grepping source files on my system I see that Cheetah, IPython, and
Mercurial, as well as stdlib's ihooks.py, all like to assign to
__builtin__.__import__.  (And ihooks.py is buggy: its replacement for
__import__ does not accept a 'level' argument.  No wonder it's called
"undocumented" and "may become obsolete" in the documentation.)


Incidentally, http://docs.python.org/library/functions.html#__import__
claims that the 'level' argument was added in Python 2.5, but
/usr/lib/python2.5/encodings/__init__.py doesn't pass a level argument
to __import__, and therefore doesn't trigger the error.

Hope that helps
Marius Gedminas
-- 
Ambition is a poor excuse for not having enough sense to be lazy.

Attachment: signature.asc
Description: Digital signature

Reply via email to