python - 带有烧瓶的 rets-python 不能作为 json 返回
问题描述
我正在做一个与 相关的项目rets
,不知何故我的合作者在安装过程中使用rets-client
for有问题。js
无论如何,所以我决定找到python
我rets-python
从https://github.com/opendoor-labs/rets找到的
我能够从返回的数据rets
,不知何故我想做一个api
所以我安装了flask
(新的烧瓶)
但是我试图将数据返回到JSON
我只是不断收到错误
我这是我的代码
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)
我将在这里写下我的回报,因为我尝试了几种不同的回报
# 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
我尝试将结果放入 dict 中,例如dict(search_result.data)
这给了我类似的错误TypeError: cannot convert dictionary update sequence element #0 to a sequence
如果我试图得到这是 我试图得到print(type(search_result.data[0].data))
的回报,而且无论有没有这一条记录,我都会收到此错误<class 'collections.OrderedDict'>
jsonify
json.dump
Response
dict()
TypeError: Decimal('1152') is not JSON serializable
也print(type(search_result.data))
给tuple
任何人都可以帮我解决这个问题吗?
提前感谢您的任何帮助和建议。
解决方案
推荐阅读
- r - 如何在 R 中对 table1 函数中的行进行子集化?
- javascript - 如何使用 react-phone-input-2 包中的 PhoneInput 显示错误消息?
- image-processing - 多类分类之前的图像背景去除/掩蔽 - 想法?
- r - Lme4:循环 glmer 时的随机效应错误
- r - 如何设置有条件的均匀分布随机数的最大值?
- razor - 如何修复 Blazor/Razor 警告:属性值中出现意外的字符序列
- javascript - 在 div 中显示名字和姓氏的第一个字母,在 JavaScript 中只有一个输入
- node.js - 尝试导出多个 module.exports 时出错
- php - 在本地机器上下载一个 xml 文件而不保存它(php)
- java - context.getExternalFilesDirs(null) 不返回 Android 11 (API 30) 的 SD 卡目录