Проблема с кодом Python AttributeError: у объекта 'NoneType' нет атрибута 'title' - PullRequest
0 голосов
/ 30 июня 2018

Я пытаюсь запустить следующий код ниже, и он продолжает сбой с ошибкой из заголовка:

Traceback (последний вызов был последним): Файл "/usr/local/lib/python2.7/dist-packages/cherrypy/_cprequest.py", строка 670, в ответе response.body = self.handler () Файл "/usr/local/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", строка 217, в вызов self.body = self.oldhandler (* args, ** kwargs) Файл "/usr/local/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", строка 61, в вызов вернуть self.callable (* self.args, ** self.kwargs) Файл "web / 800-53-server.py", строка 79, в семье control_list.append ('% s-% d -% s'% (id, control, id, control, sc.title.title)) AttributeError: у объекта 'NoneType' нет атрибута 'title'

Блок кода, в котором, по-видимому, произошла ошибка, находится ниже:

@cherrypy.expose
def family(self, id="AC", format="html"):
    id = id.upper()
    family_control_count =  {"AC": 25, "AU": 16, "AT": 5, "CM": 11, "CP": 13, "IA": 11, "IR": 10, "MA": 6, "MP": 8,
        "PS": 8, "PE": 20, "PL": 9, "PM": 16, "RA": 6, "CA": 9, "SC": 44, "SI": 17, "SA": 22}
    families = {"AC": "Access Control", "AU": "Audit and Accountability", "AT": "Awareness and Training", "CM": "Configuration Management",
        "CP": "Contingency Planning", "IA": "Identification and Authentication", "IR": "Incident Response", "MA": "Maintenance",
        "MP": "Media Protection", "PS": "Personnel Security", "PE": "Physical and Environmental Protection", "PL": "Planning",
        "PM": "Program Management", "RA": "Risk Assessment", "CA": "Security Assessment and Authorization",
        "SC": "System and Communications Protection", "SI": "System and Information Integrity", "SA": "System and Services Acquisition"}

    control_list = []
    for control in range(1,family_control_count[id]+1):
        sc = SecControl("%s-%d" % (id, control))
        control_list.append('<div><a href="/control?id=%s-%d">%s-%d</a> - %s</div>' % (id, control, id, control, sc.title.title))

    return """<html>

Другие программы ниже:

`#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, os.path
import sys
import random
import string
import json
import yaml
import cherrypy
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('web/templates'))

sys.path.append(os.path.join('lib'))
sys.path.append(os.path.join('data'))
from seccontrol import SecControl
from seccontrolviz import SecControlViz
from utilities import *


class StringGenerator(object):
    @cherrypy.expose
    def index(self):
        return """<html>
          <head>
            <title>800-53 Controls</title>
            <link rel="stylesheet" type="text/css" href="/assets/css/main.css">
          </head>`

1 Ответ

0 голосов
/ 30 июня 2018

Пакет GovReady (который, как я предполагаю, используется на основе операторов импорта) опирается на xsltproc. Вполне вероятно, что он установлен на вашей Mac OS, но не на других компьютерах. Он должен быть установлен с sudo apt install xsltproc или эквивалентным для вашего вкуса Linux, потому что это не пакет pip.

Попробуйте запустить xsltproc --stringparam controlnumber 'AC-1' control2json.xsl ../data/800-53-controls.xml из каталога 800-53-server/lib. Вызываемая функция является оболочкой для этой команды.

После установки этой программы я получаю

{ "id": "AC-1",
  "title": "ACCESS CONTROL POLICY AND PROCEDURES",
...
}
...