我正在编写一个大致遵循这个例子的应用程序。
当我提交邮件请求时:
curl http://localhost:5000/todos -d "data=Remember the milk" -X POST
我从RethinkDB得到以下错误:
rethinkdb/ast.py", line 118, in run return c._start(self, **global_optargs) AttributeError: 'function' object has no attribute '_start'
以前有人遇到过这种事吗?我在Python3.5.0和Flask0.10.1中使用了RethinkDB 2.2.2。
谢谢,
阿洛
发布于 2016-01-02 18:27:35
代码中有一个简单的错误,我没有注意到r.connect,而没有注意到r.connect()
发布于 2016-01-02 18:27:25
这可能是类似的问题,https://github.com/rethinkdb/rethinkdb/issues/3211。
在这一行中,示例如下:
inserted = r.table('todos').insert(request.json).run(g.rdb_conn)我假设它需要JSON格式的数据,所以如果您的request.data是JOSN格式的字典,就应该进行验证。而且,JSON格式数据中的属性应该是utf8编码的字符串,而不是unicode。我不确定
curl http://localhost:5000/todos -d "data=Remember the milk" -X POST生成JSON格式的正文,如{ data:“记住牛奶”}要发送到服务器,但我建议您在那里添加其他逻辑,并验证来自客户端的数据是否已损坏并遵循正确的数据模式。类似于:
@app.route("/todos", methods=['POST'])
def new_todo():
client_data = json.loads(request.data)
object_to_be_inserted = {
'property1': client_data['property1].encode('utf-8') if 'property1' in client_data else '',
'property2': client_data['property2].encode('utf-8') if 'property2' in client_data else ''
}
inserted = r.table('todos').insert(object_to_be_inserted).run(g.rdb_conn)
return jsonify(id=inserted['generated_keys'][0])https://stackoverflow.com/questions/34568350
复制相似问题