【发布时间】:2023-04-08 04:14:02
【问题描述】:
在将图像上传到 AWS S3 时,我在 Scrapy 中得到了BotoServerError,因为它恰好是服务器停机。如何处理这些错误,以便将项目管道设置为休眠一段时间并重新尝试上传?
2016-11-17 05:59:55 [twisted] CRITICAL:
Traceback (most recent call last):
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\twisted\python\threadpool.py", line 246, in inContext
result = inContext.theWork()
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\twisted\python\threadpool.py", line 262, in <lambda>
inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\twisted\python\context.py", line 81, in callWithContext
return func(*args,**kw)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\s3\key.py", line 1426, in set_contents_from_string
encrypt_key=encrypt_key)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\s3\key.py", line 1293, in set_contents_from_file
chunked_transfer=chunked_transfer, size=size)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\s3\key.py", line 750, in send_file
chunked_transfer=chunked_transfer, size=size)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\s3\key.py", line 951, in _send_file_internal
query_args=query_args
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\s3\connection.py", line 668, in make_request
retry_handler=retry_handler
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "D:\Kerja\HIT\PYTHON~1\<project_name>\<project_name>\lib\site-packages\boto\connection.py", line 1028, in _mexe
raise BotoServerError(response.status, response.reason, body)
BotoServerError: BotoServerError: 503 Service Unavailable
【问题讨论】:
-
我认为 Scrapy 的 S3 上传处理程序不会重试。除了迁移到 boto3(有 an open issue for this)之外,我不确定是否有简单的修复方法
-
您也可以尝试安装
botocore(如果可用,scrapy 将使用botocore而不是boto)。似乎 botocore 做了一些重试(不过我找不到太多关于它的细节) -
谢谢!
boto3解决了! -
这可能是因为
boto3依赖于botocore所以安装它也安装了botocore。 (Scrapy 不使用boto3。)
标签: python amazon-web-services amazon-s3 scrapy boto