ImportError: No module named webopenid #168

Closed
ShinNoNoir opened this Issue Jul 29, 2012 · 1 comment

Comments

Projects
None yet
1 participant
@ShinNoNoir

Environment

  • Windows 7 x64
  • Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
  • web.py 0.37
  • python-openid 2.2.1

Bug

The following simple web.py + OpenID example does not work:

import web
from web import webopenid

urls = (
    '/', 'index',
    '/openid', 'webopenid.host',
)
app = web.application(urls, globals())

class index:
  def GET(self):
    oid = webopenid.status()
    if not oid:
        body = '''
        <html><head><title>Web.py OpenID Test</title></head>
        <body>
            %s
        </body>
        </html>
        ''' % webopenid.form('/openid')
    else:
        body = '''
        <html><head><title>Web.py OpenID Test</title></head>
        <body>
            Logged in!<p>%s
        </body>
        </html>
        ''' % webopenid.form('/openid')
    return body

app.run()

Given this small example, when a user enters his OpenID URL in the presented web form and clicks "log in", the following exception is thrown:

Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\web\application.py", line 239, in process
    return self.handle()
  File "C:\Python26\Lib\site-packages\web\application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "C:\Python26\Lib\site-packages\web\application.py", line 416, in _delegate
    mod = __import__(mod, None, None, [''])
ImportError: No module named webopenid

Workaround

Now, I'm not familiar with web.py's internals in order to propose a fix, but I did manage to come up with a workaround:

import web
from web import webopenid

# BEGIN WORKAROUND
import sys
sys.modules['webopenid'] = webopenid
# END OF WORKAROUND

# <rest of code>
@ShinNoNoir

This comment has been minimized.

Show comment Hide comment
@ShinNoNoir

ShinNoNoir Jul 29, 2012

Okay, I figured it out. The example I based my code on was incorrect. The problem is apparently in urls:

urls = (
    '/', 'index',
    '/openid', 'webopenid.host',
)

Should be instead:

urls = (
    '/', 'index',
    '/openid', 'web.webopenid.host',
)

Or even better, avoid strings when possible:

urls = (
    '/', 'index',
    '/openid', webopenid.host,
)

Okay, I figured it out. The example I based my code on was incorrect. The problem is apparently in urls:

urls = (
    '/', 'index',
    '/openid', 'webopenid.host',
)

Should be instead:

urls = (
    '/', 'index',
    '/openid', 'web.webopenid.host',
)

Or even better, avoid strings when possible:

urls = (
    '/', 'index',
    '/openid', webopenid.host,
)

@ShinNoNoir ShinNoNoir closed this Jul 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment