【问题标题】:Batch Requests into ArangoDB failing批量请求到 ArangoDB 失败
【发布时间】:2016-09-30 01:10:46
【问题描述】:

我正在尝试将数千条记录导入 Arango。我正在尝试使用 Arango 的批量/批量导入功能:https://docs.arangodb.com/3.0/HTTP/BatchRequest/index.html 进行 PUT 和 POST 请求的组合,以插入新记录或更新现有记录(如果它们已经存在)。我的最终解决方案需要从 Python 脚本运行,大概是使用 pyArango。我创建了一个示例 HTTP 请求

POST http://<arango_server>:8529/_db/myDB/_api/batch

看起来像下面这样:

Content-Type: multipart/form-data; boundary=P1X7QNCB
Content-Length: <calculated by python or REST Client>
Authorization: Basic <calculated by python requests session or REST Client>

--P1X7QNCB
Content-type: application/x-arango-batchpart
Content-Id: 1

POST /_api/document/model/foo HTTP/1.1


{"data": "bar"}
--P1X7QNCB

我无法在 Arango 中成功处理此问题。我尝试过使用类似于以下的python(即使我对下面代码的近似有错别字,也会生成上述请求):

url = "/_api/document/" + collection + "/" + nodeKey + " HTTP/1.1"
postString = ("--P1X7QNCB\r\n"
              "Content-type: application/x-arango-batchpart\r\n"
              "Content-Id: " + str(counter) +  "\r\n"
              "\r\n"
              "\r\n"
              "PUT " + url+ "\r\n\r\n\r\n" + json.dumps(nodeData) + "\r\n")
batchHeaders = {"Content-Type": "multipart/form-data; boundary=P1X7QNCB"}
response = self.db.connection.session.post(self.db.URL + "/batch", data=postString, headers=batchHeaders)

并使用我手动发布内容的 REST 客户端。在这两种情况下,我都会得到以下回复:

{"error":true,"errorMessage":"invalid multipart message received","code":400,"errorNum":400}

并且在arango日志文件中记录了以下内容:

WARNING received a corrupted multipart message

我做错了什么对任何人都很明显,或者我可以在哪里查找有关 ArangoDB 拒绝请求的原因的更多详细信息?

谢谢!

【问题讨论】:

    标签: arangodb pyarango


    【解决方案1】:

    ArangoDB 在尝试提取 next part of a multipart mime container 并失败时会抛出此错误。

    您应该检查您的边界字符串,并检查最后一个字符串是否以两个尾随破折号正确终止容器 (--)

    NGrepWireshark 往往对检查程序真正发送的内容非常有用 - 它有时可能与您的想法不同 - 甚至可以从其他程序中获取示例。

    【讨论】:

    • 谢谢。我错过了最终边界字符串上的终止“--”。然而,有了这个固定的 Arango 现在接受响应为 200 的多部分请求,但各个多部分响应都是: {"error":true,"errorMessage":"'METHOD' not implemented","code":501,"错误号“:9}。是否需要做一些事情来启用“批量”请求?我在 linux 上使用 ArangoDB 3.0.6 运行。
    • 更新:我让批处理发布工作。我的第二个问题是多部分标题和 POST/PUT 命令之间的双重空格。 arangod 多部分解析器似乎需要一个空格,并希望在标题之后的第二行找到“方法”。
    猜你喜欢
    • 2022-05-31
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    相关资源
    最近更新 更多