Configure a Proxy for the Google Maps Python Client
Pass a Requests proxy map through the Python Google Maps client’s requests_kwargs option.
The Python googlemaps client sends its web-service requests through Requests. Supply Requests options through the client’s requests_kwargs dictionary:
import googlemaps
gmaps = googlemaps.Client(
key=maps_api_key,
connect_timeout=5,
read_timeout=30,
requests_kwargs={
'proxies': {
'http': 'http://proxy.example:8080',
'https': 'http://proxy.example:8080',
},
},
)
maps_api_key is the application’s existing API key. Use this gmaps instance for the intended calls. An HTTP candidate from the HTTP proxy list can supply the route for a permitted public Maps API request when the selected session has no proxy credentials.
The proxies value is a map from destination scheme to proxy URL. It is not a host/port tuple or a single unstructured proxy string. An HTTPS destination can use the HTTP proxy endpoint shown here.
The client merges these options into the Requests call it makes. A standalone requests.get elsewhere in the application does not configure this client, and another googlemaps.Client constructed without these options has its own setup.
For a longer-lived integration that already owns a Requests session, the library also accepts requests_session. Keep the session’s policy and ownership deliberate when sharing it. The API key still authenticates the Maps request; proxy credentials, if required, belong in the intermediary’s supported authentication arrangement.