Exemplo n.º 1
0
def get_traceback(traceback, err):
    """Вывод ошибки"""

    traceback = str(''.join(
        traceback.format_exception(etype=type(err),
                                   value=err,
                                   tb=err.__traceback__)))
    return traceback.replace('\n', "<br></br>")
Exemplo n.º 2
0
def report_failed_processing(page_id):
    notification_timestamp = get_notification()

    fail_type = str(request.headers.get('type'))
    traceback = str(request.data)
    engine_version_str = str(request.headers.get('engine_version'))

    engine = get_engine_by_page_id(page_id)
    engine_version = get_engine_version(engine.id, engine_version_str)

    change_page_to_failed(page_id, fail_type, traceback, engine_version.id)

    if fail_type == "PROCESSING_FAILED" and app.config['EMAIL_NOTIFICATION_ADDRESSES'] != []:
        print(datetime.datetime.now(), notification_timestamp, (datetime.datetime.now() - notification_timestamp).total_seconds(), app.config["MAX_EMAIL_FREQUENCY"])
        if (datetime.datetime.now() - notification_timestamp).total_seconds() > app.config["MAX_EMAIL_FREQUENCY"]:
            page_db = get_page_by_id(page_id)
            request_db = get_request_by_page(page_db)
            api_key_db = get_api_key_by_id(request_db.api_key_id)

            message_body = "processing_client_hostname: {}<br>" \
                           "processing_client_ip_address: {}<br>" \
                           "owner_api_key: {}<br>" \
                           "owner_description: {}<br>" \
                           "engine_id: {}<br>" \
                           "engine_name: {}<br>" \
                           "request_id: {}<br>" \
                           "page_id: {}<br>" \
                            "page_name: {}<br>" \
                           "page_url: {}<br>" \
                           "####################<br>" \
                           "traceback:<br>{}" \
                           .format(request.headers.get('hostname'),
                                   request.headers.get('ip-address'),
                                   api_key_db.api_string,
                                   api_key_db.owner,
                                   engine.id,
                                   engine.name,
                                   request_db.id,
                                   page_db.id,
                                   page_db.name,
                                   page_db.url,
                                   traceback.replace("\n", "<br>"))

            send_mail(subject="API Bot - PROCESSING_FAILED",
                      body=message_body,
                      sender=('PERO OCR - API BOT', app.config['MAIL_USERNAME']),
                      recipients=app.config['EMAIL_NOTIFICATION_ADDRESSES'],
                      host=app.config['MAIL_SERVER'],
                      password=app.config['MAIL_PASSWORD'])

            set_notification()

    return jsonify({
        'status': 'success'}), 200
Exemplo n.º 3
0
def error_handler(error):
    import traceback
    print("******************************")
    print(error)
    print("******************************")

    traceback = str(traceback.format_exc())
    traceback_pretty = traceback.replace("\n", "<br>")

    return render_template('error.html',
                           error_text=str(error),
                           traceback=traceback_pretty)
Exemplo n.º 4
0
    def reportError(self, label, path=None, request=None):
        """
        """
        report = asUnicode(label)
        if not request:
            request = getattr(self.context, 'REQUEST', None)
        if request:
            if not path:
                if self.formula and hasattr(self.formula, 'absolute_url_path'):
                    path = self.formula.absolute_url_path()
            if path:
                report += " - Plomino formula %s" % path

            traceback = self.message.replace("<", "&lt;").replace(">", "&gt;")
            report += " - Plomino traceback " + traceback.replace(
                '\n', '\n<br/>')
            plone_tools = getToolByName(
                self.context.getParentDatabase().aq_inner, 'plone_utils')
            plone_tools.addPortalMessage(report, 'error', request)
Exemplo n.º 5
0
    def reportError(self, label, path=None, request=None):
        """
        """
        report = asUnicode(label)
        if not request:
            request = getattr(self.context, 'REQUEST', None)
        if request:
            if not path:
                if (self.formula
                        and hasattr(self.formula, 'absolute_url_path')):
                    path = self.formula.absolute_url_path()
            if path:
                report += " - Plomino formula %s" % path

            traceback = self.message.replace("<", "&lt;").replace(">", "&gt;")
            report += " - Plomino traceback " + traceback.replace(
                '\n', '\n<br/>')
            api.portal.show_message(message=report,
                                    request=request,
                                    type='error')
Exemplo n.º 6
0
    def reportError(self, label, path=None, request=None):
        """
        """
        report = asUnicode(label)
        if not request:
            request = getattr(self.context, 'REQUEST', None)
        if request:
            if not path:
                if (self.formula and
                        hasattr(self.formula, 'absolute_url_path')):
                    path = self.formula.absolute_url_path()
            if path:
                report += " - Plomino formula %s" % path

            traceback = self.message.replace("<", "&lt;").replace(">", "&gt;")
            report += " - Plomino traceback " + traceback.replace(
                '\n', '\n<br/>')
            api.portal.show_message(
                message=report,
                request=request,
                type='error'
            )
Exemplo n.º 7
0
def getSynTraceback(filename, pysplit, traceback):
    strs = traceback.replace("<string>", filename).splitlines()
    # print(strs, file=sys.stderr)
    strs = ["syn"] + [strs[0]] + strs[5:]
    return jsonify(strs)