Search code examples
deepsecurity

Trend DSM V12 SAAS API example giving "Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /api/policies"


I am trying to set up antimalware email customization on trend v12 DSM SAAS and was trying the API calls example for python given below. https://automation.deepsecurity.trendmicro.com/article/dsaas/send-request?platform=dsaas

However i am not able to establish connection and was running into connection issues and getting below error.

2019-11-12 10:24:24,653 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /api/policies 2019-11-12 10:24:24,655 WARNING Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /api/policies 2019-11-12 10:24:24,656 WARNING Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /api/policies Traceback (most recent call last):

The url ".trendmicro.com" is whitelisted in the proxy that i am using. r = s.get('https://app.deepsecurity.trendmicro.com') also returns 200 code.

There is no option for me to bypass proxy as per the network restriction it is must to send the traffic over proxy.

import deepsecurity as api
from deepsecurity.rest import ApiException as api_exception
import requests

api.Configuration.verify_ssl = False

s = requests.Session()
s.proxies = {
    "http": "http://myproxy:80",
    "https": "http://myproxy:80",
}

r = s.get('https://app.deepsecurity.trendmicro.com')

def get_policies_list(api, configuration, api_version, api_exception):
    """ Gets a list of policies on the Deep Security Manager

    :return: A PoliciesApi object that contains a list of policies.
    """

    try:
        # Create a PoliciesApi object
        policies_api = api.PoliciesApi(api.ApiClient(configuration))
        print('getting policy api configuration')
        # List policies using version v1 of the API
        policies_list = policies_api.list_policies(api_version)
        print('getting policy list')
        # View the list of policies
        return policies_list

    except api_exception as e:
        return "Exception: " + str(e)

if __name__ == '__main__':
    # Add Deep Security Manager host information to the api client configuration
    print ('first line')
    configuration = api.Configuration()
    configuration.host = 'https://app.deepsecurity.trendmicro.com/api'

    # Authentication
    configuration.api_key['api-secret-key'] = 'mysecretkey'

    # Version
    api_version = 'v1'
    print ('executing the api call')
    print(get_policies_list(api, configuration, api_version, api_exception))

Is there some other settings that i need to do to establish the connection. Please let me know.


Solution

  • thanks for sharing your question. I believe I have a solution for you!

    Looking at the code, I see you're setting up proxies using the 'requests' library. Then, the rest of the code is based on an example from our Automation Center, which uses the Deep Security Python SDK library. This means that the request being sent by the SDK code is not going through the proxies you have defined, which would explain the error messages you're seeing.

    In terms of a fix, I would suggest adding a proxy to the configuration object. It would go right under the host line, so the code would look like:

    configuration.host = 'https://app.deepsecurity.trendmicro.com/api'
    configuration.proxy = 'http://myproxy:80'
    

    Please let me know if that works for you. If so, you could remove all the 'requests' code from the file.

    P.S. I work for Trend Micro in R&D for Deep Security.