当前位置: 首页>>代码示例>>Python>>正文


Python Request.data方法代码示例

本文整理汇总了Python中six.moves.urllib.request.Request.data方法的典型用法代码示例。如果您正苦于以下问题:Python Request.data方法的具体用法?Python Request.data怎么用?Python Request.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.urllib.request.Request的用法示例。


在下文中一共展示了Request.data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _action

# 需要导入模块: from six.moves.urllib.request import Request [as 别名]
# 或者: from six.moves.urllib.request.Request import data [as 别名]
    def _action(self, params, body=None, content_type=None):
        # about token, see https://github.com/bittorrent/webui/wiki/TokenSystem
        url = self.base_url + '?token=' + self.token + '&' + urlencode(params)
        request = Request(url)

        if body:
            request.data = body
            request.add_header('Content-length', len(body))
        if content_type:
            request.add_header('Content-type', content_type)

        response = self.opener.open(request)
        return response.code, json.loads(response.read())
开发者ID:SerhatG,项目名称:nzbToMedia,代码行数:15,代码来源:client.py

示例2: submit

# 需要导入模块: from six.moves.urllib.request import Request [as 别名]
# 或者: from six.moves.urllib.request.Request import data [as 别名]
def submit(recaptcha_response_field,
           secret_key,
           remoteip,
           verify_server=VERIFY_SERVER):
    """
    Submits a reCAPTCHA request for verification. Returns RecaptchaResponse
    for the request

    recaptcha_response_field -- The value from the form
    secret_key -- your reCAPTCHA secret key
    remoteip -- the user's ip address
    """

    if not (recaptcha_response_field and len(recaptcha_response_field)):
        return RecaptchaResponse(
            is_valid=False,
            error_code='incorrect-captcha-sol'
        )

    def encode_if_necessary(s):
        if isinstance(s, six.text_type):
            return s.encode('utf-8')
        return s

    if six.PY2:
        secret_key = encode_if_necessary(secret_key)
        remoteip = encode_if_necessary(remoteip)
        recaptcha_response_field = encode_if_necessary(
            recaptcha_response_field)

    params = parse.urlencode({
        'secret': secret_key,
        'remoteip': remoteip,
        'response': recaptcha_response_field,
    })

    request = Request(
        url="https://{0}/recaptcha/api/siteverify".format(verify_server),
        data=params,
        headers={
            "Content-type": "application/x-www-form-urlencoded",
            "User-agent": "noReCAPTCHA Python"
        }
    )

    if six.PY3:
        request.data = request.data.encode('utf-8')

    httpresp = urlopen(request)

    return_values = json.loads(httpresp.read())
    httpresp.close()

    return_code = return_values['success']
    error_codes = return_values.get('error-codes', [])

    if return_code:
        return RecaptchaResponse(is_valid=True)
    else:
        return RecaptchaResponse(
            is_valid=False,
            error_code=error_codes
        )
开发者ID:plone,项目名称:plone.formwidget.recaptcha,代码行数:65,代码来源:norecaptcha.py


注:本文中的six.moves.urllib.request.Request.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。