smartystreets / smartystreets-python-sdk

The official client libraries for accessing SmartyStreets APIs from Python 2.7 and 3.5
https://smartystreets.com/docs/sdk/python
Apache License 2.0
28 stars 30 forks source link

Failure in address verification #40

Closed viettappcard closed 1 year ago

viettappcard commented 1 year ago

Hi guys, this is throwing errors for all our flows with address verification.

Cause

Looks to be changes from https://github.com/smartystreets/smartystreets-python-sdk/commit/ce388d5a7e66f43712d321249477cf5f4359b6d3 at smartystreets_python_sdk/us_street/client.py line 73, lookup.match was replaced with lookup.match.value, which throws the error.

-         add_field(converted_lookup, 'match', lookup.match)
+         add_field(converted_lookup, 'match', lookup.match.value)

Error

AttributeError
'str' object has no attribute 'value'

Code example

client_builder = ClientBuilder(credentials)
client_builder.max_timeout = 3
client = client_builder.with_licenses(
    ["us-core-cloud"]
).build_us_street_api_client()

lookup = Lookup()
lookup.street = address_data["street"]
lookup.city = address_data["city"]
lookup.state = address_data["state"]
lookup.country = address_data["country"]
lookup.zipcode = address_data["zip"]
lookup.match = "enhanced"

try:
    client.send_lookup(lookup)
except exceptions.SmartyException as err:
    # never gets here
RyanLCox1 commented 1 year ago

Lookup matches are now part of an enum. So, your code should be changed to

lookup.match = MatchType.ENHANCED

viettappcard commented 1 year ago

Thanks @RyanLCox1 , will try this out. I was looking for the release notes for this breaking change but it seems there wasn't any? Also, won't the below never be reached because there is "enhanced" there instead of MatchType.ENHANCED.value? https://github.com/smartystreets/smartystreets-python-sdk/blob/090117d2c1c95879c2ddbdceed980e8d150b9d31/smartystreets_python_sdk/us_street/client.py#L58

viettappcard commented 1 year ago

@RyanLCox1 we've tested and looks like things are fine now, but we do want to note this has been a very unexpected change

RyanLCox1 commented 1 year ago

I've pushed a new version that is backward compatible with string values for the MatchType.

I've also included a fix for the above lookup.match == 'enhanced'

Thank you for your feedback!