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

International Autocomplete Lookup - AttributeError: 'str' object has no attribute 'get' #35

Closed xiaokiddzhang closed 2 years ago

xiaokiddzhang commented 2 years ago

Hi,

When I test the International Autocomplete Lookup SDK (version 4.10.6) with following code:

from smartystreets_python_sdk import StaticCredentials, ClientBuilder from smartystreets_python_sdk.international_autocomplete import Lookup as InternationalAutocompleteLookup

auth_id = '********'
token = '*********'
credentials = StaticCredentials(auth_id, token)
client = ClientBuilder(credentials).with_licenses(
    ["international-autocomplete-cloud"]).build_international_autocomplete_api_client()
lookup = InternationalAutocompleteLookup('Louis')
lookup.country = "FRA"
suggestions = client.send(lookup)

I got an exception - AttributeError: 'str' object has no attribute 'get' Following are trackback:

Traceback (most recent call last): File "/Users/xz/Documents/GitHub/python-tool/smarty_street/main.py", line 102, in run_international_lookup() File "/Users/xz/Documents/GitHub/python-tool/smarty_street/main.py", line 77, in run_international_lookup suggestions = client.send(lookup) # The client will also return the suggestions directly File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/client.py", line 29, in send suggestions = self.convert_suggestions(result or []) File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/client.py", line 47, in convert_suggestions return [Suggestion(suggestion) for suggestion in suggestion_dictionaries] File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/client.py", line 47, in return [Suggestion(suggestion) for suggestion in suggestion_dictionaries] File "/Users/xz/Documents/GitHub/python-tool/.venv/lib/python3.9/site-packages/smartystreets_python_sdk/international_autocomplete/suggestion.py", line 3, in init self.street = obj.get('street', None) AttributeError: 'str' object has no attribute 'get'

PS: The US AutoComplete Lookup is working fine

xiaokiddzhang commented 2 years ago

I think there is a bug on this line: https://github.com/smartystreets/smartystreets-python-sdk/blob/b4ba1805a231d586fdc9d22a5f1e4e8ac0fc5e77/smartystreets_python_sdk/international_autocomplete/client.py#L29 It should be: suggestions = self.convert_suggestions(result.get('candidates') or [])

DuncanBeutler commented 2 years ago

Thanks for catching that! You can get the updated code on version 4.10.7

xiaokiddzhang commented 2 years ago

Thanks for catching that! You can get the updated code on version 4.10.7

Thanks @DuncanBeutler !