问题描述
这与 Zapier Python 代码有关.有没有人成功使用 pop_list()
函数作为 StoreClient 库?我被困在这个简单的程序上.基本上,我试图删除存储在 MyList.get('MyIDList') 中的列表中的第一项
This is related to the Zapier Python code. Has anyone been successful using the pop_list()
function as part of the StoreClient library? I'm stuck on this simple program. Basically i'm trying to remove the first item in my list that is stored in MyList.get('MyIDList')
非常感谢任何帮助.
下面是我的代码.请注意,如果我删除第二行,它会正常工作.我的清单肯定不是空的.
Below is my code. Note if I remove the 2nd line, it'll work fine. My list is certainly not empty.
MyList= StoreClient('STSecretKey')
MyList.list_pop('MyIDList', location='head')
return {'FirstItem':MyList.get('MyIDList')[0]}
错误信息:
Traceback (most recent call last):
File "/tmp/tmpPToKk0/usercode.py", line 9, in the_function
MyList.list_pop('MyIDList', location='head')
File "/var/task/store_api.py", line 226, in list_pop
return self.call('patch', BASE_URL, json=data)
File "/var/task/store_api.py", line 61, in call
raise StoreCallException(json['error'])
StoreCallException: list is empty
推荐答案
这里是 David,来自 Zapier 平台团队.很难说到底出了什么问题,但我最好的猜测是你的列表实际上不是一个列表.您可以通过转到 https://store.zapier.com/api/来快速验证这一点record?secret=STSecretKey,它显示了存储在数据库中的 JSON.如果正确,它看起来像这样:
David here, from the Zapier Platform team. It's hard to tell exactly what's wrong, but my best guess is that your list isn't actually a list. You can quickly verify this by going to https://store.zapier.com/api/records?secret=STSecretKey, which shows the JSON that's stored in the database. If it's correct, it'll look like this:
{
"MyIDList": {
"list": [
1,
2,
3
]
}
}
为了生成上述内容,我运行了以下代码:
To generate the above, I ran the following code:
store = StoreClient('davidkey')
store.list_push('MyIDList', 1)
store.list_push('MyIDList', 2)
store.list_push('MyIDList', 3)
popped = store.list_pop('j', location='head') # got 1
accessed = store.get('j')[0] # got error
您会注意到最后一行为我生成了一个错误.鉴于它对您有用(但从列表中弹出不适用),我猜您反而有一个 0
键,其中包含数据.如果您确保使用 list_push
来填充您的存储,它应该会按预期工作.
You'll notice that the last line generated an error for me. Given that it works for you (but popping off the list doesn't), I'm guessing that you instead have a key of 0
that has data in it. If you make sure to use list_push
to populate your storage, it should work as expected.
这篇关于如何使用list_pop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!