无法使动力发电机扫描与Boto配合使用 [英] Trouble getting a dynamodb scan to work with boto

查看:54
本文介绍了无法使动力发电机扫描与Boto配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用boto访问一个dynamodb表。一切顺利,直到我尝试执行扫描操作为止。

I'm using boto to access a dynamodb table. Everything was going well until I tried to perform a scan operation.

我尝试了几次反复搜索Internet之后发现的语法,但是没有运气:

I've tried a couple of syntaxes I've found after repeated searches of The Internet, but no luck:

def scanAssets(self, asset):
    results = self.table.scan({('asset', 'EQ', asset)})
         -or-
    results = self.table.scan(scan_filter={'asset':boto.dynamodb.condition.EQ(asset)})

我要扫描的属性称为资产,资产是字符串。

The attribute I'm scanning for is called 'asset', and asset is a string.

奇怪的是table.scan调用总是通过此函数结束:

The odd thing is the table.scan call always ends up going through this function:

def dynamize_scan_filter(self, scan_filter):
    """
    Convert a layer2 scan_filter parameter into the
    structure required by Layer1.
    """
    d = None
    if scan_filter:
        d = {}
        for attr_name in scan_filter:
            condition = scan_filter[attr_name]
            d[attr_name] = condition.to_dict()
    return d

我不是python专家,但是我不知道这将如何工作。即

I'm not a python expert, but I don't see how this would work. I.e. what kind of structure would scan_filter have to be to get through this code?

同样,也许scan_filter必须是什么样的结构?也许我只是在说错了。有任何建议吗?

Again, maybe I'm just calling it wrong. Any suggestions?

推荐答案

好,看来我有导入问题。只需使用:

OK, looks like I had an import problem. Simply using:

import boto

并指定boto.dynamodb.condition不会削减它。我必须添加:

and specifying boto.dynamodb.condition doesn't cut it. I had to add:

import dynamodb.condition

获取要获取的条件类型。我现在工作的代码是:

to get the condition type to get picked up. My now working code is:

results = self.table.scan(scan_filter={'asset': dynamodb.condition.EQ(asset)})

并不是我完全理解为什么,但是它现在对我有用。 :-)

Not that I completely understand why, but it's working for me now. :-)

这篇关于无法使动力发电机扫描与Boto配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆