0
@tornado.web.authenticated
@tornado.web.asynchronous
@tornado.gen.coroutine
def post(self):

    try:
        files_body = self.request.files['file']
    except:
        error_msg = u"failed to upload file"
        error_msg = self.handle_error(error_msg)
        self.finish(dict(is_succ=False, error_msg=error_msg))
        return

    file_ = files_body[0]
    filename = file_['filename']

    # asynchronous request, obtain OCR info
    files = [('image', filename, file_['body'])]
    fields = (('api_key', config.OCR_API_KEY), ('api_secret', config.OCR_API_SECRET))
    content_type, body = encode_multipart_formdata(fields, files)

    headers = {"Content-Type": content_type, 'content-length': str(len(body))}

    request = tornado.httpclient.HTTPRequest(config.OCR_HOST, method="POST", headers=headers, body=body,
                                             validate_cert=False, request_timeout = 30)

    try:
        response = yield tornado.httpclient.AsyncHTTPClient().fetch(request)
    except Exception, e:
        logging.error(u'orc timeout {}'.format(e))
        error_msg = u"OCR timeout"
        error_msg = self.handle_error(error_msg)
        self.finish(dict(is_succ=False, error_msg=error_msg))
        return
    if not response.error and response.body:
        data = json.loads(response.body)
        self.extra_info(data)
        result = dict(is_succ=True, error_msg=u"", data=data)
    else:
        result = dict(is_succ=False, error_msg=u"request timeout", data={})
    self.finish(result)

as the code shown, I want to write an api to handle id-card picture upload, and post a request to third part interface for getting the information of id-card.

This api can run well on my PC,however it timeouts on Testing Server. I cannot figure out where the problem is.

  • Can you show a stacktrace (use `logging.exception` instead of `logging.error`)? The exception handling is misleading, it could be a different error than timeout – kwarunek Jul 24 '17 at 07:27
  • I set request_timeout=30.And I use logging.exception instead of logging.error, the most valuable info I get is "CurlError: HTTP 599: Operation timed out after 30000 milliseconds with 0 bytes received ." No more important message – Weiguo Yun Jul 24 '17 at 09:24

0 Answers0