Skip to content

When I use with flask, I got a error #1

@Aleftherian

Description

@Aleftherian

My code:

from hcaptcha.hcaptcha import HCaptchaVerifier, HCaptchaVerificationError
hcaptcha_client = HCaptchaVerifier(secret_key="")

@public_blueprint.route('/signup', methods=['GET', 'POST'])
def signup():
	if request.method=="POST":

		hcatpcha_token=request.form.get('hcatpcha_token')
		nickname=request.form.get('nickname')

		nombre=request.form.get('name1')
		apellido=request.form.get('name2')

		email=request.form.get('email')
		password=request.form.get('password')

		try:
			is_valid = asyncio.run(hcaptcha_client.verify(hcatpcha_token))
			if is_valid:
				cuenta=Accounts(username="", password=password, gmail=email, number="", nombre=" ", apellido="", genero="", fecha_nacimiento="", fecha_registro=datetime.now(), VIP="")
				db.session.add(cuenta)
				db.session.commit()
			else:
				print("Captcha INvalido")
				return render_template('public/signup.html', msg="No haz completado el captcha!")
		except Exception as e:
			return e

	return render_template('public/signup.html', msg="Hello World")

I post to /signup

TypeError
TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a HCaptchaVerificationError.
Traceback (most recent call last)
    File "/home/krootca/nulltech/lib/python3.11/site-packages/flask/app.py", line 1466, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/krootca/nulltech/lib/python3.11/site-packages/flask/app.py", line 1463, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/krootca/nulltech/lib/python3.11/site-packages/flask/app.py", line 873, in full_dispatch_request
    return self.finalize_request(rv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^

    File "/home/krootca/nulltech/lib/python3.11/site-packages/flask/app.py", line 892, in finalize_request

    response = self.make_response(rv)
               ^^^^^^^^^^^^^^^^^^^^^^ [Open an interactive python shell in this frame] 

    File "/home/krootca/nulltech/lib/python3.11/site-packages/flask/app.py", line 1201, in make_response

    raise TypeError(
    ^

    TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a HCaptchaVerificationError.

If I can fix this I will editing this text

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions