TransWikia.com

How to Handle Proxies within Carto's Python Import API framework

Geographic Information Systems Asked by CambrianCatalyst on December 1, 2020

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:tempcartocarto_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?

One Answer

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

Answered by Jorge Sanz on December 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP