gcloud recaptcha enterprise -创建评估



我正在通过ReCaptcha企业教程工作,并且遇到了400 Request contains an invalid argument错误。我用的是Django。

我按照这里的说明https://cloud.google.com/recaptcha-enterprise/docs/create-assessment#python验证验证码。

我已经能够在前端加载验证码与此代码

{% block content %}
<script type="text/javascript">
var onloadCallback = function() {
grecaptcha.enterprise.render('html_element', {
'sitekey' : '{{ sitekey }}',
});
};
</script>
<form action="{% url 'captcha-authentication' %}" method="post">
{% csrf_token %}
<div id="html_element"></div>
<input type="submit" value="Submit">
</form>
<script src="https://www.google.com/recaptcha/enterprise.js?onload=onloadCallback&render=explicit"
async defer>
</script>

我已经在我的观点中验证了request.POST包含'g- recapcha -response'密钥。对于我的site_key,我使用来自https://console.cloud.google.com/security/recaptcha的密钥id。

def confirm_captcha(token, site_key, recaptcha_action):
parent_project = "t-commerce-321516"
client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient()
event = recaptchaenterprise_v1.Event()
event.site_key = site_key
event.token = token
event.expected_action = recaptcha_action
assessment = recaptchaenterprise_v1.Assessment()
assessment.event = event
request = recaptchaenterprise_v1.CreateAssessmentRequest()
request.assessment = assessment
request.parent = parent_project
# this is the line that is throwing an error
response = client.create_assessment(request)
if not response.token_properties.valid:
print("The CreateAssessment() call failed because the token was " +
"invalid for the following reasons: "
+ str(response.token_properties.invalid_reason))
else:
if response.event.expected_action == recaptcha_action:
print("The reCAPTCHA score for this token is: " +
str(response.risk_analysis.score))
return True
else:
print("The action attribute in your reCAPTCHA tag does" +
"not match the action you are expecting to score")
return False

创建客户端评估的错误是400 Request contains an invalid argument.

有没有办法告诉谷歌为什么生气?

我在前端使用一个复选框,也许这意味着recaptcha_action参数不需要,但我不确定如何做到这一点。

任何帮助或指针是感激的!

我想你需要:

request.parent = `projects/${parent_project}`

/: CreateAssessmentRequest

相关内容

  • 没有找到相关文章

最新更新