简体   繁体   English

为什么在 dynamoDB 中插入项目时,仅在 1 种情况下使用相同的变量会出现 RecursionError

[英]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.

相关问题 为什么我使用 while 或 if 无限循环得到 RecursionError - Why do I get a RecursionError using either while or if indefinite loops 批量写入DynamoDB时,为什么有时会收到“超出项目大小”消息? - Why do I sometimes get “item size exceeded” message when batch-writing into DynamoDB? 为什么在执行二分搜索算法时会出现“RecursionError”? - Why do I get “RecursionError” implementing Binary Search algorithm? 为什么更改 NaN 值后会出现 RecursionError - why do i get RecursionError after changing NaN values 为什么只有在同一行上两次调用递归函数时才出现RecursionError? - Why I'm getting a RecursionError only if I call the recursive function twice on the same line? 为什么在将元素插入python的列表框中时出现此错误 - Why do I get this error when inserting element into listbox in python 为什么在使用 py2app 编译时会收到“RecursionError:超出最大递归深度”? - Why do I receive 'RecursionError: maximum recursion depth exceeded' when compiling with py2app? 如何使用相同的变量名将项目追加到列表? - How do I append an item to a list using the same variable name? 为什么当我使用 statsmodels 进行 OLS 和使用 scikit 进行 PooledOLS 时得到相同的结果? - Why do I get the same results when I do OLS using statsmodels and PooledOLS using scikit? 为什么我得到 RecursionError:超出最大递归深度 - why I get RecursionError: maximum recursion depth exceeded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM