Skip to content

update error handling in address_validator.py #1

@kellypierce

Description

@kellypierce

The USPS shipping validation API changed the structure of return values, breaking the code in

def validate(addr_dict, credentials):

A revision would look something like this, where v is the validated address json returned by the call to usps.validate_address():

try:
     v_addr = v['AddressValidateResponse']['Address']
     if v_addr['Zip4'] != None:
         zip_code = '{}-{}'.format(v_addr['Zip5'], v_addr['Zip4'])
     else:
         zip_code = v_addr['Zip5']
     reformat_rentals.append(
         {
             'address': v_addr['Address2'],
             'city': v_addr['City'],
             'zip_code': zip_code,
             'original': v['original']
         }
     )
 except KeyError:
     print(f'Unable to parse {v}')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions