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

Fix append on None error #13

Closed jasonrfarkas closed 4 years ago

jasonrfarkas commented 4 years ago

Currently when using this sdk I get a 'NoneType' object has no attribute 'append' This should fix that error.

Let me know if I'm missing something I don't see a contribution guide or the like.

jasonrfarkas commented 4 years ago

I'll also mention that the sdk example for us_street_apit_client doesn't work either since keys are left out. They should be defaulted and/or use a getattr method to default them, but that deserves its own pr.

for now anyone facing the same issues I'm facing can just set lookup.result = [] and set the the other fields as default values as well.

MouaYing commented 4 years ago

lookup.result is set to be [] during Lookup's init function (line 12 of us_street/lookup.py at time of writing). I am unable to reproduce your error. What version of Python are you using?

DuncanBeutler commented 4 years ago

@jasonrfarkas As for the keys, you'll notice that you can either input your unique account keys in the auth_id & auth_token variables or utilize the safer method of putting them in your os environment if you uncomment the code on lines 12 & 13 of the us_street_single_address_example. Hope that helps!

jasonrfarkas commented 4 years ago

Ok this issue is very different then I thought. Let me explain what happened - you are welcome to take the feedback as you see fit.

I was doing some zip code calls - all good. I then needed to add some us_street calls. It was unclear to me that some of imports are different as the names are the same and they use the same ClientBuilder. There is also no error that will be thrown when using the wrong one initially. But since their properties are different they error out with that append to None error. It will also error out on some attribute errors (@DuncanBeutler I meant attributes where missing - not the account keys)

Using the correct lookup makes everything work. code now looks like

from smartystreets_python_sdk.us_street import Lookup as StreetLookup
from smartystreets_python_sdk.us_zipcode import Lookup as ZipLookUp

2 easy ways to help avoid this:

  1. Change the docs examples to do the above imports so its clear they Lookup objects are different
  2. Make the code care about which lookup object it receives so it errors with a clear error

for reference - although it doesn't matter - I'm on python 3.6

DuncanBeutler commented 4 years ago

https://github.com/smartystreets/smartystreets-python-sdk/commit/e666821faee1af9fdba6683f2309edbf6d1925e9