AttributeError:“ NoneType”对象没有属性“ email”

时间:2019-08-21 01:54:29

标签: python

我刚刚和邮递员测试我的数据,但是我遇到了错误

 AttributeError: 'NoneType' object has no attribute 'email'.

这是控制台中的错误:

  File "/Users/thomashunt/projects/ct-platform-api/apis/student_api.py", line 519, in put
    return StudentService.student_ldi_attendees(submission)

  File "/Users/thomashunt/projects/ct-platform-api/services/students.py", line 235, in student_ldi_attendees
    email = submission.email()
AttributeError: 'NoneType' object has no attribute 'email'

但是,这已经在下面的对象中定义了。

class studentldiattendees(object):
    def __init__(self):
        self.first_name = None
        self.last_name = None
        self.email = None
        self.student_tags: List[str] = None


    def set_model(self, model: Student):
        model.first_name = self.first_name
        model.last_name = self.last_name
        model.email = self.email
        if self.student_tags:
            TagsEdit.set_model(self, model)
        else:
            model.student_tags = []

    @staticmethod
    def from_dict(dct):
        entity = studentldiattendees()
        entity.first_name = dct.get('first_name')
        entity.last_name = dct.get('last_name')
        entity.email = dct.get('email')
        entity.student_tags = TagsEdit.from_dict(dct.get('student_tags'))

API文件

@ns.route('/student-ldi-attendees')
class studentldiattendeesEndpoint(Resource):
    @SecurityService.requires_system
    @ns.expect(student_ldi_attendees_model, validate=True)
    @ns.marshal_with(student_person_model)
    def put(self):
        logging.info('student LDI 2019 tag appended')
        submission = studentldiattendees.from_dict(request.json)

      return StudentService.student_ldi_attendees(submission)

how its being submitted


 @staticmethod
def student_ldi_attendees(submission: studentldiattendees ) -> Person:
repo = PersonData()
email = submission.email()
student = repo.find_by_email(email)

if not student:
    raise RecordNotFoundException('No Record with this email in the database')

    ldi_attendees_message = 'LDI 2019 tag added to user'

reference_fields = [EventItemReferenceField('student_ldi', 'LDI 2019 Tag added to user')],
reference_content = [ldi_attendees_message]

MessagingActivityService.create_student_event_for_action(student.id, None, student,
                                                         True,
                                                         ActionTypes.Student.value.InternalNote,
                                                         None,
                                                         reference_fields,
                                                         reference_content, None,
                                                         None, None, True, True)





StudentService.re_index(student)
return student

0 个答案:

没有答案