Skip to content

generate_presigned_url ,The obtained URL cannot be directly used for downloading. #4592

@zhaohaosen123

Description

@zhaohaosen123

Describe the bug

    presigned_download_url = s3_client.generate_presigned_url(
        'get_object',
        Params={
            'Bucket': minio_bucket,
            'Key': file_name,
            'ResponseContentDisposition': f'attachment; filename="{file_name}"'
        },
        ExpiresIn=3600  # 1小时过期
    )
    s3_client = boto3.client(
        's3',
        endpoint_url=f'http://{minio_internal_endpoint}',
        aws_access_key_id=minio_access_key,
        aws_secret_access_key=minio_secret_key,
        region_name='cn-north-1',
        config=Config(
            signature_version='s3v4',
            region_name='cn-north-1',
            s3={'addressing_style': 'path'}
        )
    )

The obtained URL failed to load when accessed through the browser.

InvalidRequest
The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.
/onlyoffice/963194ca-64a6-4b87-ab2d-43d8680271e5.docx
185BE78893937C6B
dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

(base) PS E:\python代码\simulation> pip install boto3
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting boto3
Downloading https://mirrors.aliyun.com/pypi/packages/19/18/33047424f098d5b832362c23404800f607b601a0ad08d7ccb0ddc285efba/boto3-1.40.10-py3-none-any.whl (140 kB)
Collecting botocore<1.41.0,>=1.40.10 (from boto3)
Downloading https://mirrors.aliyun.com/pypi/packages/a4/f5/2f30a927a30c1d04763bfe8a8ec5f9ad635047078ca630233b1888a7f39f/botocore-1.40.10-py3-none-any.whl (14.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.0/14.0 MB 7.4 MB/s eta 0:00:00
Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in e:\anaconda\lib\site-packages (from boto3) (1.0.1)
Collecting s3transfer<0.14.0,>=0.13.0 (from boto3)
Downloading https://mirrors.aliyun.com/pypi/packages/6d/4f/d073e09df851cfa251ef7840007d04db3293a0482ce607d2b993926089be/s3transfer-0.13.1-py3-none-any.whl (85 kB)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in e:\anaconda\lib\site-packages (from botocore<1.41.0,>=1.40.10->boto3) (2.9.0.post0)
Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in e:\anaconda\lib\site-packages (from botocore<1.41.0,>=1.40.10->boto3) (2.5.0)
Requirement already satisfied: six>=1.5 in e:\anaconda\lib\site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.41.0,>=1.40.10->boto3) (1.17.0)
Installing collected packages: botocore, s3transfer, boto3
Attempting uninstall: botocore
Found existing installation: botocore 1.34.69
Uninstalling botocore-1.34.69:
Successfully uninstalled botocore-1.34.69
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
aiobotocore 2.12.3 requires botocore<1.34.70,>=1.34.41, but you have botocore 1.40.10 which is incompatible.
Successfully installed boto3-1.40.10 botocore-1.40.10 s3transfer-0.13.1

[notice] A new release of pip is available: 24.3.1 -> 25.2
[notice] To update, run: python.exe -m pip install --upgrade pip

Current Behavior

    presigned_download_url = s3_client.generate_presigned_url(
        'get_object',
        Params={
            'Bucket': minio_bucket,
            'Key': file_name,
            'ResponseContentDisposition': f'attachment; filename="{file_name}"'
        },
        ExpiresIn=3600  # 1小时过期
    )
    s3_client = boto3.client(
        's3',
        endpoint_url=f'http://{minio_internal_endpoint}',
        aws_access_key_id=minio_access_key,
        aws_secret_access_key=minio_secret_key,
        region_name='cn-north-1',
        config=Config(
            signature_version='s3v4',
            region_name='cn-north-1',
            s3={'addressing_style': 'path'}
        )
    )

The obtained URL failed to load when accessed through the browser.

InvalidRequest
The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.
/onlyoffice/963194ca-64a6-4b87-ab2d-43d8680271e5.docx
185BE78893937C6B
dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8

Reproduction Steps

(base) PS E:\python代码\simulation> pip install boto3
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting boto3
Downloading https://mirrors.aliyun.com/pypi/packages/19/18/33047424f098d5b832362c23404800f607b601a0ad08d7ccb0ddc285efba/boto3-1.40.10-py3-none-any.whl (140 kB)
Collecting botocore<1.41.0,>=1.40.10 (from boto3)
Downloading https://mirrors.aliyun.com/pypi/packages/a4/f5/2f30a927a30c1d04763bfe8a8ec5f9ad635047078ca630233b1888a7f39f/botocore-1.40.10-py3-none-any.whl (14.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.0/14.0 MB 7.4 MB/s eta 0:00:00
Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in e:\anaconda\lib\site-packages (from boto3) (1.0.1)
Collecting s3transfer<0.14.0,>=0.13.0 (from boto3)
Downloading https://mirrors.aliyun.com/pypi/packages/6d/4f/d073e09df851cfa251ef7840007d04db3293a0482ce607d2b993926089be/s3transfer-0.13.1-py3-none-any.whl (85 kB)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in e:\anaconda\lib\site-packages (from botocore<1.41.0,>=1.40.10->boto3) (2.9.0.post0)
Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in e:\anaconda\lib\site-packages (from botocore<1.41.0,>=1.40.10->boto3) (2.5.0)
Requirement already satisfied: six>=1.5 in e:\anaconda\lib\site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.41.0,>=1.40.10->boto3) (1.17.0)
Installing collected packages: botocore, s3transfer, boto3
Attempting uninstall: botocore
Found existing installation: botocore 1.34.69
Uninstalling botocore-1.34.69:
Successfully uninstalled botocore-1.34.69
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
aiobotocore 2.12.3 requires botocore<1.34.70,>=1.34.41, but you have botocore 1.40.10 which is incompatible.
Successfully installed boto3-1.40.10 botocore-1.40.10 s3transfer-0.13.1

[notice] A new release of pip is available: 24.3.1 -> 25.2
[notice] To update, run: python.exe -m pip install --upgrade pip

Possible Solution

    presigned_download_url = s3_client.generate_presigned_url(
        'get_object',
        Params={
            'Bucket': minio_bucket,
            'Key': file_name,
            'ResponseContentDisposition': f'attachment; filename="{file_name}"'
        },
        ExpiresIn=3600  # 1小时过期
    )
    s3_client = boto3.client(
        's3',
        endpoint_url=f'http://{minio_internal_endpoint}',
        aws_access_key_id=minio_access_key,
        aws_secret_access_key=minio_secret_key,
        region_name='cn-north-1',
        config=Config(
            signature_version='s3v4',
            region_name='cn-north-1',
            s3={'addressing_style': 'path'}
        )
    )

The obtained URL failed to load when accessed through the browser.

InvalidRequest
The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.
/onlyoffice/963194ca-64a6-4b87-ab2d-43d8680271e5.docx
185BE78893937C6B
dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8

Additional Information/Context

No response

SDK version used

1.40.10

Environment details (OS name and version, etc.)

windows python 3.10

Metadata

Metadata

Labels

bugThis issue is a confirmed bug.p2This is a standard priority issueresponse-requestedWaiting on additional information or feedback.s3

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions