

S3へアクセスする際に例外エラーが発生してアクセスできません。  
対処方法などあれば教えて頂けませんでしょうか。

プロキシ周りの設定を変更する必要があるのかその辺りの知見がなく、アドバイス頂けると幸いです。  
よろしくお願いします。

**実行環境**

ネットワーク: 社内ネットワーク  
Windows10 Pro  
Python 3.7.9  
各パッケージ

[code]

    Package         Version
    boto3           1.16.25
    botocore        1.19.25
    jmespath        0.10.0
    pip             20.2.4
    python-dateutil 2.8.1
    s3transfer      0.3.3
    selenium        3.141.0
    setuptools      47.1.0
    six             1.15.0
    urllib3         1.26.2
    wheel           0.35.1
    
[/code]

### 発生している例外エラー

[code]

    Traceback (most recent call last):
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
        self._prepare_proxy(conn)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
        conn.connect()
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 359, in connect
        conn = self._connect_tls_proxy(hostname, conn)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 502, in _connect_tls_proxy
        ssl_context=ssl_context,
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 429, in ssl_wrap_socket
        sock, context, tls_in_tls, server_hostname=server_hostname
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 472, in _ssl_wrap_socket_impl
        return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
        session=session
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 870, in _create
        self.do_handshake()
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
        self._sslobj.do_handshake()
    ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\httpsession.py", line 263, in send
        chunked=self._chunked(request.headers),
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen
        method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\retry.py", line 506, in increment
        raise six.reraise(type(error), error, _stacktrace)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\packages\six.py", line 734, in reraise
        raise value.with_traceback(tb)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
        self._prepare_proxy(conn)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
        conn.connect()
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 359, in connect
        conn = self._connect_tls_proxy(hostname, conn)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 502, in _connect_tls_proxy
        ssl_context=ssl_context,
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 429, in ssl_wrap_socket
        sock, context, tls_in_tls, server_hostname=server_hostname
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 472, in _ssl_wrap_socket_impl
        return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
        session=session
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 870, in _create
        self.do_handshake()
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
        self._sslobj.do_handshake()
    urllib3.exceptions.ProxyError: ('Cannot connect to proxy.', ConnectionResetError(10054, '既存の接続はリモート ホストに強制的に切断されました。', None, 10054, None))
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "test.py", line 7, in <module>
        Prefix='sample/'
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 357, in _api_call
        return self._make_api_call(operation_name, kwargs)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 663, in _make_api_call
        operation_model, request_dict, request_context)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 682, in _make_request
        return self._endpoint.make_request(operation_model, request_dict)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 102, in make_request
        return self._send_request(request_dict, operation_model)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 137, in _send_request
        success_response, exception):
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 256, in _needs_retry
        caught_exception=caught_exception, request_dict=request_dict)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 356, in emit
        return self._emitter.emit(aliased_event_name, **kwargs)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 228, in emit
        return self._emit(event_name, kwargs)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 211, in _emit
        response = handler(**kwargs)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 183, in __call__
        if self._checker(attempts, response, caught_exception):
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 251, in __call__
        caught_exception)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 277, in _should_retry
        return self._checker(attempt_number, response, caught_exception)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 317, in __call__
        caught_exception)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 223, in __call__
        attempt_number, caught_exception)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 359, in _check_caught_exception
        raise caught_exception
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 200, in _do_get_response
        http_response = self._send(request)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 269, in _send
        return self.http_session.send(request)
      File "C:\Users\user001\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\httpsession.py", line 285, in send
        raise ProxyConnectionError(proxy_url=proxy_url, error=e)
    botocore.exceptions.ProxyConnectionError: Failed to connect to proxy URL: "https://Proxy:8080"
    
[/code]

### コード

[code]

    import boto3
    
    client = boto3.client('s3')
    
    response = client.list_objects(
        Bucket='bucket001',
        Prefix='sample/'
    )
    
    for item in response['Contents']:
        print('{} : {}'.format(item['Key'],item['LastModified']))
    
[/code]


CC BY-SA 4.0
2020-12-02T01:44:51.590
72332
2022-01-15T13:00:20.100
2021-03-11T11:36:07.907
3060
42958
question
python amazon-s3 boto3
Python から s3 にプロキシ経由でのアクセス時に発生するエラーを解決したい


エラーメッセージに `Failed to connect to proxy URL: "https://Proxy:8080"`
と表示されているので、プロキシサーバの設定 (環境変数 `HTTP_PROXY`, `HTTPS_PROXY` の設定内容)
を確認し、必要に応じて設定を追加してみてください。

* * *

_この投稿は[@metropolis
さんのコメント](https://ja.stackoverflow.com/questions/72332/python%e3%81%a7s3%e3%81%b8%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e6%99%82%e3%81%ab%e7%99%ba%e7%94%9f%e3%81%99%e3%82%8b%e3%82%a8%e3%83%a9%e3%83%bc%e3%82%92%e8%a7%a3%e6%b1%ba%e3%81%97%e3%81%9f%e3%81%84#comment80309_72332)
の内容を元に コミュニティwiki として投稿しました。_


CC BY-SA 4.0
2021-03-11T11:32:56.893
74591
2021-03-11T11:32:56.893
3060
72332
answer