refindlyllc / rets

A thin RETS client
MIT License
69 stars 26 forks source link

Query for a ListingId that includes a "-" (dash character) using search(search_filter={}) #223

Open theodorebear opened 3 years ago

theodorebear commented 3 years ago

Hi all! Love this library and only ran into one snag so far.

While searching a Listing resource, Listing class, supplying a dict to search_filter, and the field I want to match on is "V0-215012678", which is in CRMLS (Southern California).

When running with a dict {'ListingId': 'V0-215012678'}, I get the following:

Traceback (most recent call last): File "/Users/theodorebear/Documents/closehack-mls/lib/mls.py", line 1672, in request for i,result in enumerate(results): File "/Users/theodorebear/.pyenv/versions/3.6.11/lib/python3.6/site-packages/rets/session.py", line 417, in search for res in search_cursor.generator(response=response): File "/Users/theodorebear/.pyenv/versions/3.6.11/lib/python3.6/site-packages/rets/parsers/search.py", line 52, in generator raise RETSException(msg) **rets.exceptions.RETSException: RETS Error 20206: Could not parse DMQL2 Query: Invalid character: ' at or near position 11. [...ListingId= !-->'V0-2150126]**

Converting to dmql_query='(ListingId="V0-215012678")' seemed to do the trick for me since it was a DMQL query with the item wrapped in quotes.

If this package was able to convert the single quotes in the {'ListingId': 'V0-215012678'} to double quotes, then I could stick with the search_filter={} dict method of searching, but for now I think I'll have to bypass that completely and convert all queries to DMQL.

mcrowson commented 3 years ago

Can take a look at a long term solution, but what about using double quotes in your filters?

theodorebear commented 3 years ago

aha! why didn't I think of that... it worked.

q['values'] = [f'"{v}"' for v in q['values']] 
queryDict['ListingId'] = {"$in": q['values']}