0

The lists i am passing in the pyzillow API

add_list = ['913   COMANCHE DR   OXON HILL MD ','70   CLAY ST   ANNAPOLIS MD ','9125   SCOTT ST  SPRINGFIELD VA ']
zip_list = [20745, 21401, 22153]

This is the API I am running

from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults
hometype = []

for add,zip_code in zip(add_list,zip_list):
    address = add
    zipcode = zip_code
    zillow_data = ZillowWrapper('X1-ZWz18uczm57uvf_56tmg')
    deep_search_response = zillow_data.get_deep_search_results(address, zipcode)
    result = GetDeepSearchResults(deep_search_response)
    hometype.append(result.home_type)

This runs perfectly and gives proper output

But when I use these lists

add_list_edited = ['913   COMANCHE DR   OXON HILL MD ','16640   HARWOOD OAKS CT   DUMFRIES VA ','70   CLAY ST   ANNAPOLIS MD ','9125   SCOTT ST   SPRINGFIELD VA ']
zip_list_edited = [20745, 22026, 21401, 22153]

I get following error on running the same API

TypeError: __str__ returned non-string (type dict)

I checked that the second address in list isnt specific hence the scraper is throwing error. I removed it and the code worked but the issue is I used trial and error on only 4 elements. I am working on large number of elements and after dropping values having the second address i ran the code and again it threw the same error but its virtually impossible to identify which address is giving a problem. Is there a way to add exception to the loop? I dont mind dropping values which give me errors. Any suggestion would be welcome.

Faltu Tp
  • 31
  • 1
  • 4

1 Answers1

0

Building on my previous reply, this is what I meant:

from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults, ZillowError

def getprice(address, zipcode):
    zid = 'put_api_key_here'

    zildat = ZillowWrapper(zid)
    try:
        deep_search_response = zildat.get_deep_search_results(address, zipcode)
    except ZillowError as e:
        message = e.message['text']
        code = e.message['code']
        print("Error: {code} - {message}".format(code=code, message=message))
        return 0

    result = GetDeepSearchResults(deep_search_response)
    price = result.last_sold_price
    return price
Sara M.
  • 13
  • 4