文档有附件时批量更新失败?

时间:2013-12-11 10:43:27

标签: python couchdb couchdb-python

我正在执行以下操作:

  1. 准备一些文件:docs = [ doc1, doc2, ... ]。这些文件有可能附件
  2. POST_bulk_docs文件列表
  3. 我得到Exception > Problems updating list of documents (length = 1): (500, ('badarg', '58'))
  4. 我的bulk_docs是(在这种情况下只有一个):

    [   {   '_attachments': {   'image.png': {   'content_type': 'image/png',
                                                 'data': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM8AAADkCAIAAACwiOf9AAAAA3NCSVQICAjb4U/gAAAgAElEQVR4nO...'}},
            '_id': '08b8fc66-cd90-47a1-9053-4f6fefabdfe3',
            '_rev': '15-ff3d0e8baa56e5ad2fac4937264fb3f6',
            'docmeta': {   'created': '2013-10-01 14:48:24.311257',
                           'updated': [   '2013-10-01 14:48:24.394157',
                                          '2013-12-11 08:19:47.271812',
                                          '2013-12-11 08:25:05.662546',
                                          '2013-12-11 10:38:56.116145']},
            'org_id': 45345,
            'outputs_id': None,
            'properties': {   'auto-t2s': False,
                              'content_type': 'image/png',
                              'lang': 'es',
                              'name': 'dfasdfasdf',
                              'text': 'erwerwerwrwerwr'},
            'subtype': 'voicemail-st',
            'tags': ['RRR-ccc-dtjkqx'],
            'type': 'recording'}]
    

    这是一个详细的例外:

    Traceback (most recent call last):
      File "portal_support_ut.py", line 470, in test_UpdateDoc
        self.ps.UpdateDoc(self.org_id, what, doc_id, new_data)
      File "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/ps/complex_ops.py", line 349, in UpdateDoc
        success, doc = database.UpdateDoc(doc_id, new_data)
      File "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/updater.py", line 38, in UpdateDoc
        res = self.SaveDoc(doc_id, doc)
      File "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/saver.py", line 88, in SaveDoc
        else      : self.bulk_append(doc, flush, update_revision)
      File "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/bulker.py", line 257, in bulk_append
        if force_send or flush or not self.timer.use_timer : self.BulkSend(show_progress=True)
      File "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/bulker.py", line 144, in BulkSend
        results = self.UpdateDocuments(self.bulk)
      File "/home/gonvaled/projects/new-wavilon-portal/python_modules/wav/cdb/core/bulker.py", line 67, in UpdateDocuments
        results = self.db.update(bulkdocs)
      File "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/site-packages/couchdb/client.py", line 764, in update
        _, _, data = self.resource.post_json('_bulk_docs', body=content)
      File "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/site-packages/couchdb/http.py", line 527, in post_json
        **params)
      File "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/site-packages/couchdb/http.py", line 546, in _request_json
        headers=headers, **params)
      File "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/site-packages/couchdb/http.py", line 542, in _request
        credentials=self.credentials)
      File "/home/gonvaled/.virtualenvs/python2.7.3-wavilon1/local/lib/python2.7/site-packages/couchdb/http.py", line 398, in request
        raise ServerError((status, error))
    ServerError: (500, ('badarg', '58'))
    

    badarg是什么意思?在执行_bulk_docs时是否可以发送附件?

2 个答案:

答案 0 :(得分:0)

解决方案是在将附件发送到coudhdb之前删除data:image/png;base64,前缀。

对于python替代方案,请参阅here

答案 1 :(得分:0)

在我们的邮件列表中回答了这个问题,为了完整起见,在这里重复了答案。

数据字段有两种不正确的方式;

'data': 'data:image/png;base64,iVBORw0KGgoAA....'

'data:image / png; base64',前缀错误,而base64部分格式错误(CouchDB显然需要对其进行解码以存储它)。