1

我正在尝试在 python 中使用 s3fs 连接到 s3 存储桶。关联的凭据保存在 ~/.aws/credentials 中名为“pete”的配置文件中:

[default]
aws_access_key_id=****
aws_secret_access_key=****

[pete]
aws_access_key_id=****
aws_secret_access_key=****

这似乎适用于 AWS CLI(在 Windows 上):

$>aws s3 ls s3://my-bucket/ --profile pete
                       PRE other-test-folder/
                       PRE test-folder/

但是当我使用 python 中的 s3fs 包使用应该是等效的代码时,我得到一个权限被拒绝的错误:

import s3fs
import requests

s3 = s3fs.core.S3FileSystem(profile = 'pete')
s3.ls('my-bucket')

我收到此错误:

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\s3fs\core.py", line 504, in _lsdir
    async for i in it:

  File "C:\ProgramData\Anaconda3\lib\site-packages\aiobotocore\paginate.py", line 32, in __anext__
    response = await self._make_request(current_kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\aiobotocore\client.py", line 154, in _make_api_call
    raise error_class(parsed_response, operation_name)

ClientError: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied


The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "<ipython-input-9-4627a44a7ac3>", line 5, in <module>
    s3.ls('ma-baseball')

  File "C:\ProgramData\Anaconda3\lib\site-packages\s3fs\core.py", line 993, in ls
    files = maybe_sync(self._ls, self, path, refresh=refresh)

  File "C:\ProgramData\Anaconda3\lib\site-packages\fsspec\asyn.py", line 97, in maybe_sync
    return sync(loop, func, *args, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\fsspec\asyn.py", line 68, in sync
    raise exc.with_traceback(tb)

  File "C:\ProgramData\Anaconda3\lib\site-packages\fsspec\asyn.py", line 52, in f
    result[0] = await future

  File "C:\ProgramData\Anaconda3\lib\site-packages\s3fs\core.py", line 676, in _ls
    return await self._lsdir(path, refresh)

  File "C:\ProgramData\Anaconda3\lib\site-packages\s3fs\core.py", line 527, in _lsdir
    raise translate_boto_error(e) from e

PermissionError: Access Denied

我必须假设这不是 s3 中的配置问题,因为我可以通过 CLI 访问 s3。所以我的 s3fs 代码一定有问题,但我找不到关于 s3fs 中配置文件的大量文档来弄清楚发生了什么。任何帮助当然表示赞赏。

4

0 回答 0