server.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:farfetchd 作者: isislovecruft 项目源码 文件源码
def render_GET(self, request):
        """Retrieve a ReCaptcha from the API server and serve it to the client.

        :type request: :api:`twisted.web.http.Request`
        :param request: A ``Request`` object for a CAPTCHA.
        :rtype: str
        :returns: A JSON blob containing the following fields:
             * "version": The Farfetchd protocol version.
             * "image": A base64-encoded CAPTCHA JPEG image.
             * "challenge": A base64-encoded, encrypted challenge.  The client
               will need to hold on to the and pass it back later, along with
               their challenge response.
             * "error": An ASCII error message.
            Any of the above JSON fields may be "null".
        """
        image, challenge = self.getCaptchaImage(request)

        json = {
            'data': {
                'id': 1,
                'type': self.responseType,
                'version': FARFETCHD_API_VERSION,
                'image': image,
                'challenge': challenge, # The challenge is already base64-encoded
            }
        }

        try:
            json["data"]["image"] = base64.b64encode(image)
        except Exception as err:
            log.err("Could not construct or encode captcha!")
            log.err(err)

        return self.formatResponse(json, request)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号