Reputation: 2198
I am doing a project which has to do with rets
, somehow my collaborator has problem using rets-client
for js
during installation.
Anyways, so I decided to find python
instead which I found rets-python
from https://github.com/opendoor-labs/rets
I am able to get data returned from rets
, somehow I wanted to make an api
so I installed flask
(new with flask)
However I tried to return the data into JSON
I just kept on getting errors
I this is my code
import json
from flask import Flask, Response, jsonify
app = Flask(__name__)
@app.route('/')
def mls():
from rets.client import RetsClient
client = RetsClient(
login_url='xxxxxxxxxxxx',
username='xxxxxxxxxxxx',
password='xxxxxxxxxxxxx',
# Ensure that you are using the right auth_type for this particular MLS
# auth_type='basic',
# Alternatively authenticate using user agent password
user_agent='xxxxxxxxxxxxxxxx',
user_agent_password='xxxxxxxxxxxxxxxx'
)
resource = client.get_resource('Property')
print(resource)
resource.key_field
print(resource.key_field)
resource_class = resource.get_class('RD_1')
print(resource_class)
search_result = resource_class.search(query='(L_Status=1_0)', limit=2)
I will write my returns here as I have tried few different returns
# return jsonify(results=search_result.data)
# TypeError: <Record: Property:RD_1:259957852> is not JSON serializable
return Response(json.dumps(search_result.data), mimetype='application/json')
# TypeError: <Record: Property:RD_1:259957852> is not JSON serializable
return json.dumps(search_result.data)
# TypeError: <Record: Property:RD_1:259957852> is not JSON serializable
I event tried making the results into dict such as dict(search_result.data)
which gives me errors like TypeError: cannot convert dictionary update sequence element #0 to a sequence
if I try to get the print(type(search_result.data[0].data))
this is the return <class 'collections.OrderedDict'>
I tried to jsonify
, json.dump
and also with Response
with just this one record with or without dict()
I get this error TypeError: Decimal('1152') is not JSON serializable
also print(type(search_result.data))
gives tuple
Anyone able to give me a hand on this?
Thanks in advance for any help and advises.
Upvotes: 0
Views: 141