NewBeginning
NewBeginning

Reputation: 41

How to use Boto3 S3 connection with proxy?

I want to write the Python script to download from S3 bucket using Boto3. My code is working fine when not using proxy, but I have to run this under proxy. I have set proxy in the Boto3.client(config=) and I get the following error.

Proxy set as:

s3 = boto3.client('s3',
                      aws_access_key_id = usrkey,
                      aws_secret_access_key = sctkey,
                      region_name = 'eu-west-2',
                      config=Config(proxies={'http': '<proxy-server>:<port>'})
                      )

still end up with the error

    Traceback (most recent call last):
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

and at the end:

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL:"<URL>".

I can connect using WinSCP to AWS-S3, with proxy, that is working fine. But it pops up a warning message that I have to accept every time, by clicking ok. What is the problem here, I don't understand with Python.

Upvotes: 3

Views: 4955

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202088

Make sure your <proxy-server> is a host name:

config=Config(proxies={'http': 'example.com:port'}

Not a URL:

config=Config(proxies={'http': 'http://example.com:port'}

Upvotes: 2

Related Questions