A JSON object {"name": "newname"}
needs to be passed as request body. The new name can not be passed as URL path parameter. The problem is the implementation of collection.action()
:
def action(self, method, action, **params) :
"a generic fct for interacting everything that doesn't have an assigned fct"
fct = getattr(self.connection.session, method.lower())
r = fct(self.URL + "/" + action, params = params)
return r.json()
The keyword arguments end up as dict called params
. This object is passed to the request function fct()
as named parameter params
. This parameter receives the dict and converts it to URL path parameters, e.g. ?name=newname
which is not supported by the HTTP API of the server.
There is unfortunately no way to pass a payload via action()
. You can write some custom code however:
from pyArango.connection import *
connection = Connection('http://localhost:8529', username='root', password='')
try:
connection.createDatabase('test-db')
except CreationError:
pass
test_db = Database(connection, 'test-db')
try:
test_db.createCollection(name='new')
except CreationError:
pass
collection = test_db['new']
r = connection.session.put(collection.URL + '/rename', data='{"name":"newname"}')
print(r.text)
collection = test_db['newname']
You can also use a dict for the payload and transform it to JSON if you want:
import json
...put(..., data=json.dumps({"name": "newname"}))