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

us_autocomplete client throws a TypeError if the response is null #15

Closed dmbrady01 closed 4 years ago

dmbrady01 commented 4 years ago

Hey guys,

When using the us_autocomplete client, it looks like the response.payload can return {"suggestions": None}, which trips up convert_suggestions. Maybe casting None to an empty list would be appropriate here?

In [100]: lookup = Lookup('4338 Hayman Ave, La Canada, CA 91011')
In [101]:  client.send(lookup)
~/miniconda2/envs/hydra/lib/python3.8/site-packages/smartystreets_python_sdk/us_autocomplete/client.py in send(self, lookup)
     27
     28         result = self.serializer.deserialize(response.payload)
---> 29         suggestions = self.convert_suggestions(result.get('suggestions', []))
     30         lookup.result = suggestions
     31

~/miniconda2/envs/hydra/lib/python3.8/site-packages/smartystreets_python_sdk/us_autocomplete/client.py in convert_suggestions(suggestion_dictionaries)
     55     @staticmethod
     56     def convert_suggestions(suggestion_dictionaries):
---> 57         return [Suggestion(suggestion) for suggestion in suggestion_dictionaries]
     58
     59     @staticmethod

TypeError: 'NoneType' object is not iterable
MouaYing commented 4 years ago

Thank you, @dmbrady01 ! This has just been fixed, and version 4.4.1 contains the change.