-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quart compatibility #7
Comments
I have added the compatibility with Quart into the dev branch. It is not yet well tested, but it works in my environment. You can give it a try. |
To use the plugin in Quart, remember to set the config |
Still getting the same error |
Are you using the dev branch? |
Yes |
Is the config HCAPTCHA_ASYNC entry set to True? |
Yes |
Could you verify and paste the id() of the following variables in the plugin here?
|
I'm sorry wdym? |
Add else:
self.verify = self.verify_sync
try:
request = flask_request
except NameError:
print("flask_hcaptcha: Missing dependencies")
exit()
print(id(flask_request), id(quart_request), id(request))
@app.context_processor
def get_code():
return dict(hcaptcha=Markup(self.get_code())) |
Also, how you initialize the plugin? Through hCaptcha(app) or hcaptcha.init_app(app)? |
I use hCaptcha(app) |
These are the ids btw: 140065711599920 140065728038752 140065728038752 |
Try to use init_app instead. I noticed there could be a bug for hCaptcha(app) during development of quart compatibility. |
Looks fine. Does it work now? |
Oh ok it was my fault for the previous error, I somehow managed to clone the main branch even after double checking. Anyway now even if the captcha is correct await hcaptcha.verify() returns False |
Could you provide detailed step for me to reproduce the problem? |
Just a post request and in the endpoint I tried using:
and It Is printing false |
Here is an example, see if /submit return a correct value in your environment. from quart import Quart, render_template_string
from flask_hcaptcha import hCaptcha
app = Quart(__name__)
app.config["HCAPTCHA_ASYNC"] = True
app.config["HCAPTCHA_ENABLED"] = True
app.config["HCAPTCHA_SITE_KEY"] = "<site key>"
app.config["HCAPTCHA_SECRET_KEY"] = "<secret key>"
hcaptcha = hCaptcha(app)
@app.route("/")
async def index():
return await render_template_string(
"""
<form method="post" action="/submit">
{{ hcaptcha }}
<input type="submit">
</form>
"""
)
@app.route("/submit", methods=["POST"])
async def hello():
if await hcaptcha.verify():
return "True"
else:
return "False"
if __name__ == "__main__":
app.run() |
I made my own hcaptcha handler. anyway I tried this and looks like it's working |
I will leave this open until next release. |
Released in 0.7.0. |
Is there any way to make this work in quart?
I followed the readme and I'm getting this error when i try to check hcaptcha.verify():
"RuntimeError: Working outside of request context.
This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem."
The text was updated successfully, but these errors were encountered: