Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 webpy app going in circles
#1
I am working on a web.py app which makes it so a captcha has to be given to see a page. I found some code with Google where someone had aleady done this and made it fit my app. However, it is kind of vague, and I can't seem to get it work. Even when I enter the captcha properly, it says incorrect captcha. I've done something wrong, but web.py isn't well documented and learning it seems all about changing stuff and seeing what happens. I am absolutely stumped at this point as to why the captcha doesn't validate.

import web
from web import form
from captcha import getCaptcha

render = web.template.render('templates/')

urls = (
        '/([a-zA-Z]+/[a-zA-Z]+)', 'index',
        '/', 'index',
        '/captcha.gif', 'captchaimg',
        '/captcha', 'captcha'
        )

app = web.application(urls, globals())

if web.config.get("_session") is None:
    session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={'captcha': ''})
    web.config._session = session
else:
    session = web.config._session

vcaptcha = form.Validator('Please enter the code', lambda x:x == session.captcha)

enquiry_form = form.Form(
        form.Textbox("captcha", vcaptcha, description="Validation Code", pre="<img src='/captcha.gif' valign=center><br>", class_="standard", style="width:70px;"),
        )

class index:
    def GET(self, argu = "Anonymous/Person"):
        try:
            if (not session.captchad):
                web.seeother("/captcha")                
        except AttributeError:
            web.seeother("/captcha")

        args = argu.split('/')
        firstname = args[0]
        if (len(args) >= 2):
            lastname = args[1]
            return render.index(firstname, lastname)
        return render.index(firstname, "Snow")

class captcha:
    def GET(self):
        f = enquiry_form()
        return render.captcha(f)
    def POST(self):
        f = enquiry_form()
        if not f.validates():
            return render.captcha(f)
        else:
            session.captchad = True
            web.seeother("/")

class captchaimg:
    def GET(self):
        web.header("Content-Type", "image/gif")
        captcha = getCaptcha()
        session.captcha = captcha[0]
        return captcha[1].read()

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
I believe the problem might be with line 22 which I barely understand:
Quote
#2
did you mean to use web3? web was last updated August 3, 2005, and their web site is closed.
Quote
#3
(Feb-25-2019, 03:45 PM)Larz60+ Wrote: did you mean to use web3? web was last updated August 3, 2005, and their web site is closed.

No, I mean this: http://webpy.org/

You can just do this to get the prerequisites...
$ pip install webpy
Quote
#4
Ok, that's a different from what I see on PyPi.org which points to this site: http://www.pythonweb.org/web/
Sorry, I'm not at all familiar with this site.

A bit of searching found this tutorial: http://webpy.org/tutorial2.en

Also please note that in 10 months support for python 2.7 ends, so perhaps it's time to upgrade?
Quote
#5
(Feb-25-2019, 03:58 PM)Larz60+ Wrote: Ok, that's a different from what I see on PyPi.org which points to this site: http://www.pythonweb.org/web/
Sorry, I'm not at all familiar with this site.

A bit of searching found this tutorial: http://webpy.org/tutorial2.en

Also please note that in 10 months support for python 2.7 ends, so perhaps it's time to upgrade?

I've done the tutorial, in fact, this code is from that but it has changed a lot since adding captcha support. webpy for python3 is still in development. I have plans to upgrade within 10 months, but I depend on webpy so I'll have to wait for it to become stable in python3.
Quote
#6
(Feb-25-2019, 04:08 PM)kintarowonders Wrote: but I depend on webpy so I'll have to wait for it to become stable in python3.
As i advice do not use web.py
Maintainer admit in issues tracker that he do not have time,and he has been advice to find someone to take over.
Use Flask is close to web.py way of working,and they have solved maintainer task with Pallets Projects(community-driven organization).
Quote
#7
(Feb-25-2019, 06:00 PM)snippsat Wrote:
(Feb-25-2019, 04:08 PM)kintarowonders Wrote: but I depend on webpy so I'll have to wait for it to become stable in python3.
As i advice do not use web.py
Maintainer admit in issues tracker that he do not have time,and he has been advice to find someone to take over.
Use Flask is close to web.py way of working,and they have solved maintainer task with Pallets Projects(community-driven organization).

Please comment no further with these non-answers. I am sticking with web.py for this project.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)