首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在QueryResult (python cloudant)上使用get_attachment调用?

如何在QueryResult (python cloudant)上使用get_attachment调用?
EN

Stack Overflow用户
提问于 2017-12-06 10:17:47
回答 0查看 273关注 0票数 0

我一直在尝试从Cloudant中的文档中获取附件图像数据。一旦选择了一个文档(用_id直接提取,等等),我就可以成功地完成。

现在尝试使用选择器结合"query“操作,我遇到了麻烦。

这是我的代码。

代码语言:javascript
复制
targetName="chibika33"
targetfile="chibitest.png"

#--------------------------------------------------
# get all the documents with the specific nameField 
#--------------------------------------------------
myDatabase.create_query_index(fields = ['nameField'])
selector = {'nameField': {'$eq': targetName}}
docs = myDatabase.get_query_result(selector)

#--------------------------------------------------
# get the attachment files to them, save it locally
#--------------------------------------------------
count = 0
for doc in docs:
    count=count+1
    result_filename="result%03d.png"%(count)

    dataContent = doc.get_attachment(targetfile, attachment_type='binary')  
    dataContentb =base64.b64decode(dataContent)    
    with open(result_filename,'wb') as output:
        output.write(dataContentb)

导致错误为;

代码语言:javascript
复制
Traceback (most recent call last):
  File "view8.py", line 44, in <module>

   dataContent = doc.get_attachment(targetfile, attachment_type='binary')
AttributeError: 'dict' object has no attribute 'get_attachment'

到目前为止,我在python-cloudant- document ...python-cloudant document:http://python-cloudant.readthedocs.io/en/latest/index.html中找不到任何将dict转换为document对象的API

任何建议都将不胜感激。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47665798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档