每次尝试发送非空的有效负载时,我都会遇到使用gharial创建顶点的问题。
一个简单的代码,例如:
import requests
url = "http://localhost:8529/_db/test_db/_api/gharial/MyGraph/vertex/Humans"
payload = {"name" : "tesla"}
r = requests.post(url, data = payload)
返回:<Response [500]>
使用以下正文:
A runtime error occurred while executing an action: SyntaxError: Unexpected token a SyntaxError: Unexpected token a
at Object.parse (native)
at Object.requestFunctions.body ([object Object]:23:21)
at extractElement (/usr/share/arangodb/js/server/modules/org/arangodb/foxx/request_context.js:56:18)
at /usr/share/arangodb/js/server/modules/org/arangodb/foxx/request_context.js:75:45
at execute (/usr/share/arangodb/js/server/modules/org/arangodb/actions.js:951:7)
at next (/usr/share/arangodb/js/server/modules/org/arangodb/actions.js:968:7)
at [object Object]:169:5
at execute (/usr/share/arangodb/js/server/modules/org/arangodb/actions.js:951:7)
at Object.routeRequest (/usr/share/arangodb/js/server/modules/org/arangodb/actions.js:972:3)
at Function.actions.defineHttp.callback (/usr/share/arangodb/js/actions/api-system.js:52:15)
This error was triggered by the following route {"path":"/_api/gharial/[^/]+/vertex/[^/]+","regexp":{},"prefix":false,"depth":5,"urlParameters":{"graph":2,"collection":4},"callback":{"options":{},"methods":["DELETE","GET","HEAD","OPTIONS","POST","PUT","PATCH"]},"route":{"url":{"match":"/:graph/vertex/:collection","methods":["post"],"constraint":{"graph":"/[^/]+/","collection":"/[^/]+/"}},"action":{},"docs":{"parameters":[{"name":"vertex","paramType":"body","description":"The document to be stored","dataType":"vertex"},{"paramType":"path","name":"graph","description":"Name of the graph.","dataType":"string"},{"paramType":"path","name":"collection","description":"Name of the vertex collection.","dataType":"string"},{"paramType":"query","name":"waitForSync","description":"define if the request should wait until synced to disk.","dataType":"boolean"}],"errorResponses":[{"code":404,"reason":"Graph or collection not found."}],"httpMethod":"POST","nickname":"post_graph_vertex_collection","summary":"Create a new vertex.","notes":"\nStores a new vertex with the information contained\nwithin the body into the given collection.\n"},"context":"/"}}
我正在运行ArangoDB 2.2.6。
感谢您的帮助,
答案 0 :(得分:3)
HTTP 500的原因是POST请求不是JSON编码的。
我认为如果代码调整为:
,它应该可行import requests
import json
url = "http://localhost:8529/_db/test_db/_api/gharial/MyGraph/vertex/Humans"
payload = {"name" : "tesla"}
r = requests.post(url, data = json.dumps(payload))