Forums

boto3 unable to connect to Proxy URL?

.

def get_boto_object():
    return boto3.client(
        's3',
        endpoint_url = FlaskSettings.ENDPOINT_URL,
        aws_access_key_id = FlaskSettings.AWS_ACCESS_KEY_ID,
        aws_secret_access_key = FlaskSettings.AWS_SECRET_KEY,
        region_name = FlaskSettings.AWS_REGION_NAME
    )

I have the endpoint URL set as https://s3.eu-west-2.wasabisys.com.

I then have this:

s3 = get_boto_object()
url = s3.generate_presigned_url(
    'get_object',
    Params={
        'Bucket': current_app.config['S3_DATABASE_NAME'],
        'Key': key
    },
    ExpiresIn=10 # expires in ten seconds
)

For some reason, when using this code it's showing this error:

proxyconnectionerror: Failed to connect to proxy URL: "http://proxy.server:3128"

It appears PythonAnywhere connects through a proxy server before routing to URLs, which is why this error didn't appear on my local machine.

Any help as to what may be causing this would be great; is the proxy server down or is there something I need to do to fix this on my end?

I've e-mailed the support e-mail RE: adding the other wasabi endpoint URLs to their whitelist, I'm assuming this is the issue.

I can see a bunch of successful connections s3 buckets in our proxy logs, but I also see a bunch of failures. The failures are all of the kind where the client (i.e. boto) has disconnected before the response was fully sent back.

What is the rest of the traceback you're getting?

Here's the full traceback:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 696, in urlopen self._prepare_proxy(conn) File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy conn.connect() File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 366, in connect self._tunnel() File "/usr/local/lib/python3.9/http/client.py", line 903, in _tunnel raise OSError(f"Tunnel connection failed: {code} {message.strip()}") OSError: Tunnel connection failed: 403 Forbidden During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/botocore/httpsession.py", line 254, in send urllib_response = conn.urlopen( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen retries = retries.increment( File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 506, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 734, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 696, in urlopen self._prepare_proxy(conn) File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy conn.connect() File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 366, in connect self._tunnel() File "/usr/local/lib/python3.9/http/client.py", line 903, in _tunnel raise OSError(f"Tunnel connection failed: {code} {message.strip()}") urllib3.exceptions.ProxyError: ('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/Markimus/NotionToObsidianWebsite/NotionToObsidianWebsite/processing.py", line 65, in <module> count = session_obj.generate_files() File "/home/Markimus/NotionToObsidianWebsite/NotionToObsidianWebsite/./NotionToObsidianWebsite/objects/sessionobject.py", line 7, in generate_files return self.workspace.generate_files() File "/home/Markimus/NotionToObsidianWebsite/NotionToObsidianWebsite/./NotionToObsidianWebsite/objects/workspaceobject.py", line 224, in generate_files s3.put_object( File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 357, in _api_call return self._make_api_call(operation_name, kwargs) File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 662, in _make_api_call http, parsed_response = self._make_request( File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 682, in _make_request return self._endpoint.make_request(operation_model, request_dict) File "/usr/local/lib/python3.9/site-packages/botocore/endpoint.py", line 102, in make_request return self._send_request(request_dict, operation_model) File "/usr/local/lib/python3.9/site-packages/botocore/endpoint.py", line 136, in _send_request while self._needs_retry(attempts, operation_model, request_dict, File "/usr/local/lib/python3.9/site-packages/botocore/endpoint.py", line 253, in _needs_retry responses = self._event_emitter.emit( File "/usr/local/lib/python3.9/site-packages/botocore/hooks.py", line 356, in emit return self._emitter.emit(aliased_event_name, kwargs) File "/usr/local/lib/python3.9/site-packages/botocore/hooks.py", line 228, in emit return self._emit(event_name, kwargs) File "/usr/local/lib/python3.9/site-packages/botocore/hooks.py", line 211, in _emit response = handler(kwargs) File "/usr/local/lib/python3.9/site-packages/botocore/retryhandler.py", line 183, in call if self._checker(attempts, response, caught_exception): File "/usr/local/lib/python3.9/site-packages/botocore/retryhandler.py", line 250, in call should_retry = self._should_retry(attempt_number, response, File "/usr/local/lib/python3.9/site-packages/botocore/retryhandler.py", line 277, in _should_retry return self._checker(attempt_number, response, caught_exception) File "/usr/local/lib/python3.9/site-packages/botocore/retryhandler.py", line 316, in call checker_response = checker(attempt_number, response, File "/usr/local/lib/python3.9/site-packages/botocore/retryhandler.py", line 222, in call return self._check_caught_exception( File "/usr/local/lib/python3.9/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception raise caught_exception File "/usr/local/lib/python3.9/site-packages/botocore/endpoint.py", line 200, in _do_get_response http_response = self._send(request) File "/usr/local/lib/python3.9/site-packages/botocore/endpoint.py", line 269, in _send return self.http_session.send(request) File "/usr/local/lib/python3.9/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: "http://proxy.server:3128"

Does it do that for all the things that you are trying to do on s3, or just specific actions?

This happens with any action as far as I can tell.

I had the same issue come up when using the delete_object() method with s3.

I switched to eu-west-1 and it all seems to be working now.

Not sure if it was the region change that fixed it or something done on your end.

We didn't make any changes, so I'm guessing it must have been the region move, though I don't know why that would affect anything.