Google Cloud Recaptcha Enterprise显示无效的参数错误

发布于 2025-02-05 06:59:44 字数 2123 浏览 2 评论 0原文

开发人员。

我使用以下链接将Recaptcha V2迁移到Recaptcha Enterprise。

https://cloud.google.com/recaptcha-enterprise/docs/using-功能

正在显示前端集成部分工作和Recaptcha复选框部分。

在用户提交通过recaptcha测试的表单提交表格后的后端。要验证recaptcha测试,我致电Google REST API来创建评估。

我正在使用此链接。 https://cloud.google.com/recaptcha-enterprise/ doc/create-Assessment#REST-API

函数代码以验证用户响应。

def verify_captcha_response(self, recaptcha_response):
        """
        Verify the Google Recaptcha V2 response of the request
         - if recatacha response value is more than the value set 
           on google recaptcha admin.
         - if request fail error will be raise and no response will be accept
        """

        if not recaptcha_response:
            return False

        if isinstance(recaptcha_response, list):
            recaptcha_response = recaptcha_response[0]

        url = "https://recaptchaenterprise.googleapis.com/v1/projects/%s/assessments?key=%s" % ("Project id", settings.RECAPTCHA_SITE_KEY)
        recaptcha_secret_key = settings.RECAPTCHA_SECRET_KEY,
        headers={'Content-Type': 'application/json'}
        data = {
         "event":{
           "token": recaptcha_response,
           "siteKey": recaptcha_secret_key,
           "expectedAction": "login"
          }
        }    
        response = requests.post(url, headers=headers,
                                 data=data)

        result = response.json()

        if not result['success']:
            if 'timeout-or-duplicate' in result['error-codes']:
                raise forms.ValidationError(msg.RECAPTCHA_FAILED)

            return False

        return True

我得到的回应。

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}

但是根据文档,我正在通过所有论点。

谢谢。

devs.

I am migrating my Recaptcha V2 to the Recaptcha enterprise using the below link.

https://cloud.google.com/recaptcha-enterprise/docs/using-features

the frontend integration part work and the Recaptcha checkbox part are showing.

On the backend side after the user submit the form passing the Recaptcha test. to verify the Recaptcha test, I call google REST API to create an assessment.

I am using this link.
https://cloud.google.com/recaptcha-enterprise/docs/create-assessment#rest-api

code of the function to verify user response.

def verify_captcha_response(self, recaptcha_response):
        """
        Verify the Google Recaptcha V2 response of the request
         - if recatacha response value is more than the value set 
           on google recaptcha admin.
         - if request fail error will be raise and no response will be accept
        """

        if not recaptcha_response:
            return False

        if isinstance(recaptcha_response, list):
            recaptcha_response = recaptcha_response[0]

        url = "https://recaptchaenterprise.googleapis.com/v1/projects/%s/assessments?key=%s" % ("Project id", settings.RECAPTCHA_SITE_KEY)
        recaptcha_secret_key = settings.RECAPTCHA_SECRET_KEY,
        headers={'Content-Type': 'application/json'}
        data = {
         "event":{
           "token": recaptcha_response,
           "siteKey": recaptcha_secret_key,
           "expectedAction": "login"
          }
        }    
        response = requests.post(url, headers=headers,
                                 data=data)

        result = response.json()

        if not result['success']:
            if 'timeout-or-duplicate' in result['error-codes']:
                raise forms.ValidationError(msg.RECAPTCHA_FAILED)

            return False

        return True

The response I am getting.

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}

but as per the documentation, I am passing all the arguments.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文