我有一个功能。该函数在更多线程中开始。我试图打印自己的错误消息。但是我做的并不重要,我仍然可以打印回溯。我的功能:
def getSuggestengineResultForThree(suggestengine, seed, dynamoDBLocation):
results[seed][suggestengine] = getsuggestsforsearchengine(seed, suggestengine)
for keyword_result in results[seed][suggestengine]:
o = 0
while True:
try:
allKeywords.put_item(
Item={
'keyword': keyword_result
}
)
break
except ProvisionedThroughputExceededException as pe:
if (o > 9):
addtoerrortable(keyword_result)
print('ProvisionedThroughputExceededException 10 times in getSuggestengineResultForThree for allKeywords')
break
sleep(1)
o = o + 1
print("ProvisionedThroughputExceededException in getSugestengineResult")
但是我为每个Thread获得了这样的输出:
Exception in thread Thread-562:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/Users/iTom/ownCloud/Documents/Workspace/PyCharm/Keywords/TesterWithDB.py", line 362, in getSuggestengineResultForThree
'keyword': keyword_result
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/boto3/resources/factory.py", line 518, in do_action
response = action(self, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/botocore/client.py", line 252, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/botocore/client.py", line 542, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ProvisionedThroughputExceededException) when calling the PutItem operation: The level of configured provisioned throughput for the table was exceeded. Consider increasing your provisioning level with the UpdateTable API
有人可以帮助我获得自己的打印而不是追溯吗? :)
答案 0 :(得分:2)
对于你的问题,这个答案有点迟了,但是这里有人在寻找这个答案。
当Neil回答时,boto3抛出的异常是botocore.exceptions.ClientError
。但是,您应该检查“ProvisionedThroughputExceededException”的响应错误代码,因为ClientError
可能是另一个问题。
from botocore.exceptions import ClientError
except ClientError as e:
if e.response['Error']['Code'] != 'ProvisionedThroughputExceededException':
raise
# do something else with 'e'
我正在使用Python 2.7,它可能会或可能不会产生影响。我收到的例外情况表明boto3已经在重试(最多9次),这与您的例外不同:
调用PutItem操作时发生错误(ProvisionedThroughputExceededException)(达到最大重试次数:9):超出了表的已配置预配置吞吐量级别。请考虑使用UpdateTable API提高配置级别。
答案 1 :(得分:0)
ProvisionedThroughputExceededException
实际上可能不是错误。尝试:
except botocore.exceptions.ClientError as pe:
代替。
如果这不起作用,请弄清楚错误发生在哪一行并在其中放置except
语句。