V-I-C-T-O-R / 12306

12306买票小工具
MIT License
674 stars 220 forks source link

sex_name 取不到值的时候会抛异常 #3

Closed Nxcat closed 5 years ago

Nxcat commented 5 years ago

passenger.sexName = passengerJson['sex_name'] or ''

V-I-C-T-O-R commented 5 years ago

@13610081161 这个问题估计是乘客信息不全造成的,建议将passenger.sexName = passengerJson.get('sex_name') or '',方法更改如下:

    def __getPassengerInfo(self, passengersList):
        passengersDetails = {}
        for passengerJson in passengersList:
            passenger = PassengerDetails()
            passenger.passengerName = passengerJson.get('passenger_name') or ''
            passenger.code = passengerJson.get('code') or ''
            passenger.sexCode = passengerJson.get('sex_code') or ''
            passenger.sexName = passengerJson.get('sex_name') or ''
            passenger.bornDate = passengerJson.get('born_date') or ''
            passenger.countryCode = passengerJson.get('country_code') or ''
            passenger.passengerIdTypeCode = passengerJson.get('passenger_id_type_code') or ''
            passenger.passengerIdTypeName = passengerJson.get('passenger_id_type_name') or ''
            passenger.passengerIdNo = passengerJson.get('passenger_id_no') or ''
            passenger.passengerType = passengerJson.get('passenger_type') or ''
            passenger.passengerFlag = passengerJson.get('passenger_flag') or ''
            passenger.passengerTypeName = passengerJson.get('passenger_type_name') or ''
            passenger.mobileNo = passengerJson.get('mobile_no') or ''
            passenger.phoneNo = passengerJson.get('phone_no') or ''
            passenger.email = passengerJson.get('email') or ''
            passenger.address = passengerJson.get('address') or ''
            passenger.postalcode = passengerJson.get('postalcode') or ''
            passenger.firstLetter = passengerJson.get('first_letter') or ''
            passenger.recordCount = passengerJson.get('recordCount') or ''
            passenger.totalTimes = passengerJson.get('total_times') or ''
            passenger.indexId = passengerJson.get('index_id') or ''
            passengersDetails[passenger.passengerIdNo] = passenger
        return passengersDetails
Nxcat commented 5 years ago

感谢!