On 5/3/07, drag sidious <[EMAIL PROTECTED]> wrote:
> So I am running off of the example at:
> http://pythonpaste.org/do-it-yourself-framework.html
>
> I have a lighttpd server setup with mod_scgi.
> I am using Debian Unstable and it's python-paste package version 1.3-2
> Also using the python-flup package version 0.2307-1
>
> Now the simple examples work fine. The 'hello world' and the
> 'interactive app' examples work fine for both using localhost httpserver
> from paste and flup.server.scgi.WSGIServer from flup.
>
> But when I try the more complex example it mysteriously fails and I
> can't figure out why.
>
> I realy have no clue what I am doing. All this python web stuff is very
> confusing and mystifying. It took me a few days of mucking around before
> I found paste and I am just trying to get it working so that I can start
> to play around with it.. but I can't even seem to do that.
>
> Is there a similar wsgi-->scgi thing from paste itself? I saw the 'SWAP'
> stuff and I tried using scgiserver, but I can't ever get it to work for
> me. I am sure that I am mucking that up also.
>
> So this is what I am working with:
>
> whatever.py:
> from objectpub import ObjectPublisher
>
> class Root(object):
>
>         # The "index" method:
>     def __call__(self):
>                 return '''
>         <form action="welcome">
>         Name: <input type="text" name="name">
>         <input type="submit">
>         </form>
>         '''
>
>     def welcome(self, name):
>         return 'Hello %s!' % name
>
> app = ObjectPublisher(Root())
>
> if __name__ == '__main__':
>     from flup.server.scgi import WSGIServer
>     WSGIServer(app,bindAddress=('192.168.0.50', 4000)).run()
>     #from paste import httpserver
>     #httpserver.serve(app, host='127.0.0.1', port='8080')
>
>
> And then objectpub.py
> from paste.request import parse_formvars
>
>
> class ObjectPublisher(object):
>     def __init__(self, root):
>         self.root = root
>
>     def __call__(self, environ, start_response):
>         fields = parse_formvars(environ)
>         print fields, "feilds"
>         print type(fields), "feilds type"
>         obj = self.find_object(self.root, environ)
>         print obj, "obj"
>         response_body = obj(**fields.mixed())
>         print response_body
>         start_response('200 OK', [('content-type', 'text/html')])
>         return [response_body]
>
>     def find_object(self, obj, environ):
>         path_info = environ.get('PATH_INFO', '')
>         if not path_info or path_info == '/':
>             # We've arrived!
>             return obj
>         # PATH_INFO always starts with a /, so we'll get rid of it:
>         path_info = path_info.lstrip('/')
>         # Then split the path into the "next" chunk, and everything
>         # after it ("rest"):
>         parts = path_info.split('/', 1)
>         next = parts[0]
>         if len(parts) == 1:
>             rest = ''
>         else:
>             rest = '/' + parts[1]
>         # Hide private methods/attributes:
>         assert not next.startswith('_')
>         # Now we get the attribute; getattr(a, 'b') is equivalent
>         # to a.b...
>         next_obj = getattr(obj, next)
>         # Now fix up SCRIPT_NAME and PATH_INFO...
>         environ['SCRIPT_NAME'] += '/' + next
>         environ['PATH_INFO'] = rest
>         # and now parse the remaining part of the URL...
>         return self.find_object(next_obj, environ)
>
>
> So you see I added some 'print' statements to the __call__
>
>
> When I run it I can get to the first part were you type in a name and
> can press enter.
>
> This is the output on the command line:
> $ python whatever.py
> 2007-05-03 21:17:14 : WSGIServer starting up
> 2007-05-03 21:17:26 : GET /scripts/
> MultiDict([]) feilds
> <type 'instance'> feilds type
> <__main__.Root object at 0xb79c684c> obj
>
>         <form action="welcome">
>         Name: <input type="text" name="name">
>         <input type="submit">
>         </form>
>
> 2007-05-03 21:17:32 : GET /scripts/welcome
> MultiDict([('name', 'asdf')]) feilds
> <type 'instance'> feilds type
> <__main__.Root object at 0xb79c684c> obj
> 2007-05-03 21:17:32 : Exception caught from handler
> Traceback (most recent call last):
>   File "/var/lib/python-support/python2.4/flup/server/scgi_base.py",
> line 185, in run
>     self._conn.server.handler(self)
>   File "/var/lib/python-support/python2.4/flup/server/scgi_base.py",
> line 456, in handler
>     result = self.application(environ, start_response)
>   File "/home/drag/mnt/objectpub.py", line 15, in __call__
>     response_body = obj(**fields.mixed())
> TypeError: __call__() got an unexpected keyword argument 'name'
>
>
> this is what it looks like when it runs correctly from the httpserver
> serving on http://127.0.0.1:8080
> MultiDict([]) feilds
> <type 'instance'> feilds type
> <__main__.Root object at 0xb79aa84c> obj
>
>         <form action="welcome">
>         Name: <input type="text" name="name">
>         <input type="submit">
>         </form>
>
> MultiDict([('name', 'asdf')]) feilds
> <type 'instance'> feilds type
> <bound method Root.welcome of <__main__.Root object at 0xb79aa84c>> obj
> Hello asdf!
>
>
>
> The only difference I see is the 'bound method' line. But I have no clue
> what that is or what or why it's different.
>
> Is there a different way to get this stuff working with SCGI or FastCGI?

Many of us prefer to use Pylons which makes using Paste more
enjoyable, although I can understand if you're trying to avoid using a
framework at all.

Good Luck!
-jj

-- 
http://jjinux.blogspot.com/

_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users

Reply via email to