Estore Error with stripe

27 views
Skip to first unread message

Maurice Waka

unread,
Jan 2, 2022, 4:55:56 AM1/2/22
to web2py-users
Hello I got this error when trying out the Estore app.
File "/home/maurice/web2py/applications/EStore/controllers/default.py", line 157, in pay
description="Purchase".encode('utf-8')
File "/home/maurice/web2py/gluon/contrib/stripe.py", line 115, in __init__
self.signature = sha1(repr((self.amount,self.description))).hexdigest()
TypeError: Unicode-objects must be encoded before hashing



part of the code in default is:

@auth.requires_login()
def checkout():
    if session.checkout_form and not request.post_vars:
        for key in session.checkout_form:
            db.cart_order[key].default = session.checkout_form[key]
    form = SQLFORM(db.cart_order).process(dbio=False)
    if form.accepted:
        session.checkout_form = form.vars
        redirect(URL('pay'))
    return locals()

def pay():#Not working, error # description: TypeError: Unicode-objects must be encoded before hashing
    from gluon.contrib.stripe import StripeForm
    results = price_cart()
    stripe_form = StripeForm(
        pk=STRIPE_PUBLIC_KEY,
        sk=STRIPE_SECRET_KEY,
        amount=int(100*results['total_with_shipping']),  # (amount is in cents)amount=int(100*results['total_with_shipping']),  
        currency='eur',
        currency_symbol='€',
        description="Purchase".encode('utf-8')
    )
    stripe_form.process()

Help in correcting this error will be appreciated.
Thank you

Dave S

unread,
Jan 3, 2022, 9:57:07 PM1/3/22
to web2py-users
On Sunday, January 2, 2022 at 1:55:56 AM UTC-8 mauri...@gmail.com wrote:
Hello I got this error when trying out the Estore app.
File "/home/maurice/web2py/applications/EStore/controllers/default.py", line 157, in pay
description="Purchase".encode('utf-8')
File "/home/maurice/web2py/gluon/contrib/stripe.py", line 115, in __init__
self.signature = sha1(repr((self.amount,self.description))).hexdigest()
TypeError: Unicode-objects must be encoded before hashing



This is probably a PY3-ism issue.   The value you give description in 3.10.1 is of type bytes, and the sha1 code probably expects a string.  In 2.7.18, that same expression yields an instance of type string.

/dps
Reply all
Reply to author
Forward
0 new messages