Skip to content

Self-Signed Certificates Require Code Changes #4

Description

@lusrmgr

First of all, thank you for this repo!! It was super helpful to me this morning for finding DeviceIDs to use in deeplinks!

It would be nice if you can add a flag for allowing SSL verification to be disabled. I had to make a change to NCentralClient.py to be able to query my N-Central server:

Added a session and transport with verify set to false and included it in the zeep.CachingClient() params

"""pyncentral main module."""
from __future__ import annotations

from re import search
from typing import Any

from zeep import Transport
from requests import Session
import requests
import zeep

from .exceptions import HTTPError, InvalidURL, NCentralError


class NCentralClient:
    """NCentralClient class."""

    def __init__(self, username: str, password: str, url: str) -> None:
        """NCentralClient constructor."""
        self.username = username
        self.password = password
        self.api_soap = "/dms2/services2/ServerEI2?wsdl"
        self.api_base_url = "https://" + url

        # Create a session with SSL verification disabled
        session = Session()
        session.verify = False
        transport = Transport(session=session)

        try:
            self.client = zeep.CachingClient(wsdl=self.api_base_url + self.api_soap, transport=transport)

        except requests.exceptions.ConnectionError as err:
            raise InvalidURL("A Invalid URL or Proxy error occurred") from err
        except requests.exceptions.HTTPError as err:
            raise HTTPError from err

It was very quick and dirty so I apologize for the messy imports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions