0

I am attempting to programmatically upload new data sets (tables) to Carto with the Carto Import API Python SDK. Unfortunately, I am doing this behind a proxy which is blocking me from successfully reaching the Carto API endpoint.

I have experimented with the requests and urllib libraries to successfully circumvent the proxy block, but I am not familiar with how to implement this same proxy handling within the framework of Carto's import python module. I have the proxy address and a username that can successfully connect through it.

The following code is what I am using to attempt to connect and upload a sample data set.

from carto.datasets import DatasetManager
from carto.auth import APIKeyAuthClient

USERNAME = '{username_placeholder}'

USR_BASE_URL = "https://{user}.carto.com/".format(user=USERNAME)

auth_client = APIKeyAuthClient(api_key="{api_placeholder}", base_url=USR_BASE_URL)

Local = r'C:\temp\carto\carto_test.zip'

dataset_manager = DatasetManager(auth_client)
dataset = dataset_manager.create(Local)

The error I receive when running this code is as follows:

carto.exceptions.CartoException: HTTPSConnectionPool(host='{placeholder}.carto.com', port=443): Max retries exceeded with url: /api/v1/imports/ (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))

Would anyone be able to assist in adding functionality for proxy handling?

0

CARTO Python SDK uses requests library, which follows a pretty standard practice to honor proxies declared as environment variable so maybe you should try to export HTTP_PROXY and HTTPS_PROXY. Example below from library documentation

$ export HTTP_PROXY="http://10.10.1.10:3128"
$ export HTTPS_PROXY="http://10.10.1.10:1080"

$ python
>>> import requests
>>> requests.get('http://example.org')

Give it a try and if that does not work you may want to create a ticket at the SDK tracker https://github.com/CartoDB/carto-python/issues/new

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.