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)
评论列表
文章目录