[英]Python: Why do is the traceback getting printed?
I have a function. 我有一个功能。 The function get started in some more threads.
该函数在更多线程中开始使用。 I tried to print a own error message.
我试图打印自己的错误消息。 But its not important what I do I get still the traceback printed.
但是我仍然要打印回溯的内容并不重要。 My function:
我的功能:
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")
But I get for every Thread an output like this: 但是我为每个线程得到了这样的输出:
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
Can someone help me to get my own print instead of the traceback? 有人可以帮我自己打印而不是追溯吗? :)
:)
This answer is a bit late for your question but here it is in case anyone is searching for this answer. 对于您的问题,这个答案有点晚了,但是如果有人在寻找这个答案,这里是答案。
The exception that boto3 throws is a botocore.exceptions.ClientError
as Neil has answered. boto3抛出的异常是
botocore.exceptions.ClientError
正如Neil回答的那样。 However you should check response error code for 'ProvisionedThroughputExceededException' because the ClientError
could be for another issue. 但是,您应该检查“ ProvisionedThroughputExceededException”的响应错误代码,因为
ClientError
可能是另一个问题。
from botocore.exceptions import ClientError
except ClientError as e:
if e.response['Error']['Code'] != 'ProvisionedThroughputExceededException':
raise
# do something else with 'e'
I am using Python 2.7 which may or may not make a difference. 我正在使用Python 2.7,这可能会有所不同。 The exception that I receive suggests that boto3 is already doing retries (up to 9 times) which is different from your exception:
我收到的异常表明boto3已经进行了重试(最多9次),这与您的异常不同:
An error occurred (ProvisionedThroughputExceededException) when calling the PutItem operation (reached max retries: 9): The level of configured provisioned throughput for the table was exceeded.
调用PutItem操作时发生错误(ProvisionedThroughputExceededException)(已达到最大重试次数:9):超出了为表配置的预配置吞吐量级别。 Consider increasing your provisioning level with the UpdateTable API.
考虑使用UpdateTable API提高配置级别。
It's possible that ProvisionedThroughputExceededException
is not actually the error. ProvisionedThroughputExceededException
可能实际上不是错误。 Try: 尝试:
except botocore.exceptions.ClientError as pe:
instead. 代替。
If that doesn't work, figure out what line the error is occurring on and put the except
statement there. 如果那行不通,请找出错误发生在哪一行,并将
except
语句放在那里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.