是否可以将HTTPS代理与aiobotocore Python模块一起使用?

时间:2017-09-25 06:13:29

标签: python boto3 aiohttp botocore

使用Aiobotocore网站上的示例和这样的HTTPS代理:

import asyncio
import aiobotocore
from aiobotocore.config import AioConfig as Config

AWS_ACCESS_KEY_ID = "xxx"
AWS_SECRET_ACCESS_KEY = "xxx"


async def go(loop):
    bucket = 'dataintake'
    filename = 'dummy.bin'
    folder = 'aiobotocore'
    key = '{}/{}'.format(folder, filename)

    session = aiobotocore.get_session(loop=loop)
    conf = Config(proxies={'http': '<http_proxy>:<http_proxy_port>', 'https': '<https_proxy>:<https_proxy_port>'})
    async with session.create_client('s3', region_name='us-west-2',
                                   aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
                                   aws_access_key_id=AWS_ACCESS_KEY_ID,
                                   config=conf) as client:
        # upload object to amazon s3
        data = b'\x01'*1024
        resp = await client.put_object(Bucket=bucket,
                                            Key=key,
                                            Body=data)
        print(resp)

        # getting s3 object properties of file we just uploaded
        resp = await client.get_object_acl(Bucket=bucket, Key=key)
        print(resp)

        # get object from s3
        response = await client.get_object(Bucket=bucket, Key=key)
        # this will ensure the connection is correctly re-used/closed
        async with response['Body'] as stream:
            assert await stream.read() == data

        # list s3 objects using paginator
        paginator = client.get_paginator('list_objects')
        async for result in paginator.paginate(Bucket=bucket, Prefix=folder):
            for c in result.get('Contents', []):
                print(c)

        # delete object from s3
        resp = await client.delete_object(Bucket=bucket, Key=key)
        print(resp)

loop = asyncio.get_event_loop()
loop.run_until_complete(go(loop))

我收到以下错误:

ValueError: Only http proxies are supported

是否有可能以某种方式以另一种方式将HTTPS代理与aiobotocore一起使用,或者是否可以轻松修改源代码以支持HTTPS代理?

1 个答案:

答案 0 :(得分:0)

下划线aiohttp库不支持HTTPS代理。