0

I'm writing an application that broadly follows this example.

When I submit a POST request like:

curl http://localhost:5000/todos -d "data=Remember the milk" -X POST

I get the following error from RethinkDB:

rethinkdb/ast.py", line 118, in run return c._start(self, **global_optargs) AttributeError: 'function' object has no attribute '_start'

Has anybody come across this kind of thing before? I'm using RethinkDB 2.2.2 with Python 3.5.0 and Flask 0.10.1.

Thanks,

Arlo

arlogb
  • 661
  • 1
  • 8
  • 19

2 Answers2

0

This may be similar issue https://github.com/rethinkdb/rethinkdb/issues/3211.

On this line form the example:

inserted = r.table('todos').insert(request.json).run(g.rdb_conn)

I assume It requires JSON formatted data so your request.data should be verified if it is a JOSN formatted dictionary. Also the properties in the JSON formatted data should be utf8 encoded strings instead of unicode. I am not sure if the

curl http://localhost:5000/todos -d "data=Remember the milk" -X POST

generates JSON formatted body like {data:"Remember the milk"} to be send to the server, but I would suggest you to add additional logic there and verify if the data that comes from the client is not corrupted and follows the correct data schema. Something like:

@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])
Velin Georgiev
  • 1,869
  • 13
  • 20
0

I had a simple error in the code that I didn't notice r.connect rather than r.connect()

arlogb
  • 661
  • 1
  • 8
  • 19