[英]Why do I get RecursionError only for 1 case using the same variable when inserting an item in dynamoDB
I am seeing a really strange behaviour in python 3, and boto3 when inserting an item to dynamoDB.在将项目插入 dynamoDB 时,我在 python 3 和 boto3 中看到了一个非常奇怪的行为。
# Assume that set_original() returns a dictionary
original = set_original()
# copy is an EXACT copy of original, but hardcoded.
copy = {..hardcoded "original" dictionary..}
I can confirm that both dictionaries are the same, as the following returns True:我可以确认两个字典是相同的,因为以下返回 True:
if copy == original:
return True
Right now this is failing with an enormous RecursionError: maximum recursion depth exceeded while calling a Python object
现在,这因巨大的
RecursionError: maximum recursion depth exceeded while calling a Python object
table.put_item(Item=original)
But this works just fine and successfully inserts the data in dynamodb:但这工作得很好,并成功地将数据插入到 dynamodb 中:
table.put_item(Item=copy)
What can possibly be happening?可能会发生什么? I checked and type(), and dir() return the same for both, they are basically copies of each other, but only one fails to insert, while the other one doesn't.
我检查并 type() 和 dir() 返回相同的两者,它们基本上是彼此的副本,但只有一个无法插入,而另一个没有。
Although I don't know the exact reason on why this is happening, I solved as follows: set_original()
was creating a dict in which one of the variables was not a str, but rather a beautiful soup string: <class 'bs4.element.NavigableString'>
This is okay for python, but it's not okay for dynamoDB.虽然我不知道发生这种情况的确切原因,但我解决了如下问题:
set_original()
正在创建一个字典,其中一个变量不是 str,而是一个漂亮的汤字符串: <class 'bs4.element.NavigableString'>
这对于 python 是可以的,但对于 dynamoDB 就不行了。 Solution was basically to convert all these NavigableString to str
type.解决方案基本上是将所有这些 NavigableString 转换为
str
类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.