def make_efile_client(): if DEBUG: session = Session() session.verify = False client = ZeepClient(EFILE_WEBSERVICE_URL, transport=Transport(session=session)) else: # TODO: CHECK WHEN ON PRODUCTION IF AUTH HEADER IS NEEDED AND IF SESSION.VERIFY SHOULD BE FALSE TOO client = ZeepClient(EFILE_WEBSERVICE_URL) return client
def _get_zeep_client(self, transport_to_bind=None): if not transport_to_bind: raise HPNAConnectionError( "SOAP client cannot be instantiated without a transport.") zeep_client = ZeepClient(wsdl=self._wsdl_url, transport=transport_to_bind) return zeep_client
def _request(self, method, *args, **kwargs): client = ZeepClient(self.WS[0]) kwargs['usuario'] = self.username kwargs['senha'] = self.password fn = getattr(client, 'method') return fn()
def __init__(self, api_key: Optional[str] = None): wsdl = WSDL if api_key else WSDL_SANDBOX self.endpoint = ENDPOINT if api_key else ENDPOINT_SANDBOX self.api_key = api_key or APIKEY_SANDBOX transport = Transport(session=Session()) transport.session.headers = self.headers self.client = ZeepClient(wsdl, transport=transport) self.service = None
def execute_report(client, context, report_path, delimiter=','): session = requests.Session() session.headers.update({'US-DELIMITER': delimiter}) transport = Transport(session=session) payload = {'ReportPath': report_path} zeep_client = ZeepClient(f"{client.base_url}{endpoint}", transport=transport) element = zeep_client.get_element('ns5:ReportRequest') obj = element(**payload) r = zeep_client.service.ExecuteReport(request=obj, context=context) return r['ReportKey']
def _request(self, method, *args, **kwargs): history = HistoryPlugin() client = ZeepClient(self.WS[0], plugins=[history]) kwargs['usuario'] = self.username kwargs['senha'] = self.password fn = getattr(client.service, method) # print envelope for debug purposes # node = client.create_message(client.service, method, **kwargs) # print etree.tostring(node, encoding='iso-8859-1'), 'NODE' result = fn(**kwargs) return result
def make_wathiq_client(): if DEBUG: session = Session() session.verify = False token = UsernameToken(WATHIQ_USERNAME, WATHIQ_PASSWORD) try: client = ZeepClient(WATHIQ_URL, transport=Transport(session=session), wsse=token) except Exception as e: print('EXCEPTION:make_wathiq_client -> ', e) client = None else: # TODO: CHECK ON PRODUCTION IF SESSION.VERIFY SHOULD BE FALSE TOO client = ZeepClient(WATHIQ_URL, wsse=UsernameToken(WATHIQ_USERNAME, WATHIQ_PASSWORD)) return client
def log_on_with_token(client): # print(inspect.getmembers(client)) credentials = { 'Token': client.token, 'ClientAccessKey': client.client_access_key } # Log on to get ns5:DataContext object with auth zeep_client = ZeepClient(f"{client.base_url}{endpoint}") element = zeep_client.get_element('ns5:LogOnWithTokenRequest') obj = element(**credentials) # print(inspect.getmembers(obj)) return zeep_client.service.LogOnWithToken(obj)
def _fetch_soap_ws(self, object_id): client = ZeepClient('{}/soap/Rastro.wsdl'.format( os.path.dirname(os.path.abspath(__file__)))) data = client.service.buscaEventos( usuario=self.ect_username, senha=self.ect_password, tipo='L', resultado='T', lingua='101', objetos=object_id, ) return data['objeto'][0]
def retrieve_report(client, report_key): zeep_client = ZeepClient(f"{client.base_url}{endpoint}") return zeep_client.service.RetrieveReport(_soapheaders={'ReportKey': report_key})
class Client(object): API_CLIENT = ZeepClient( 'http://sm.mlg.ru/services/CubusService.svc?singleWsdl') def __init__(self, login: str, password: str) -> None: """ :param login: str :param password: str """ self.credentials = {'Login': login, 'Password': password} def _get_response(self, service: str, *args) -> any: response = self.API_CLIENT.service.__getattr__(service)( self.credentials, *args) if 'Error' in response and response['Error']: raise MLGException(response['Error']) return response def get_report(self, report_id: str) -> any: """ :param report_id: :return: any """ return self._get_response('GetReport', report_id) def create_report(self, search_query: str, author_urls: List[str], blog_urls: List[str]) -> any: """ :param search_query: str :param author_urls: list (list of strings) :param blog_urls: list (list of strings) :return: any """ return self._get_response('CreateReport', search_query, author_urls, blog_urls) def delete_report(self, report_id: str) -> any: """ :param report_id: str :return: any """ return self._get_response('DeleteReport', report_id) def get_posts(self, report_id: str, date_from: datetime, date_to: datetime, page_index: Optional[int] = None, page_size: Optional[int] = None) -> any: """ :param report_id: str :param date_from: datetime :param date_to: datetime :param page_index: int or None :param page_size: int or None :return: any """ params = [ report_id, date_from.strftime('%Y-%m-%dT%H:%M:%S'), date_to.strftime('%Y-%m-%dT%H:%M:%S') ] if page_index: params.append(page_index) if page_size: if not page_index: params.append(50) params.append(page_size) return self._get_response('GetPosts', *params) def get_posts_by_objects(self, report_id: str, date_from: datetime, date_to: datetime) -> any: """ :param report_id: str :param date_from: datetime (like 2018-11-01T10:06:00) :param date_to: datetime (like 2018-11-01T10:06:00) :return: any """ return self._get_response('GetPostsStatsByObject', report_id, date_from.strftime('%Y-%m-%dT%H:%M:%S'), date_to.strftime('%Y-%m-%dT%H:%M:%S')) def update_report(self, report_id, search_query: str, author_urls: List[str], blog_urls: List[str]) -> any: """ :param report_id: str :param search_query: str :param author_urls: list (list of strings) :param blog_urls: list (list of strings) :return: any """ return self._get_response('UpdateReport', report_id, search_query, author_urls, blog_urls) def get_posts_with_sort(self, report_id: str, date_from: datetime, date_to: datetime, sort_type: int, page_index: int, page_size: int) -> any: """ :param report_id: str :param date_from: datetime (like 2018-11-01T10:06:00) :param date_to: datetime (like 2018-11-01T10:06:00) :param sort_type: int :param page_index: int :param page_size: int :return: any """ return self._get_response('GetPostsWithSort', report_id, date_from.strftime('%Y-%m-%dT%H:%M:%S'), date_to.strftime('%Y-%m-%dT%H:%M:%S'), sort_type, page_index, page_size) def get_posts_from_timestamp(self, report_id: str, timestamp: datetime, page_index: int, page_size: int) -> any: """ :param report_id: str :param timestamp: datetime (like 2018-11-22T10:10:00) :param page_index: int :param page_size: int :return: any """ return self._get_response('GetPostsFromTimestamp', report_id, timestamp.strftime('%Y-%m-%dT%H:%M:%S'), page_index, page_size) def create_report_by_post_urls(self, post_urls: List[str]) -> any: """ :param post_urls: list (list of strings) :return: any """ return self._get_response('CreateReportByPostUrls', post_urls) def create_report_history(self, report_id: str, date_from: datetime) -> any: """ :param report_id: str :param date_from: datetime (like 2018-11-01T10:06:00) :return: any """ return self._get_response('CreateReportHistory', report_id, date_from.strftime('%Y-%m-%dT%H:%M:%S'))
def connect(self): settings = Settings(strict=False, xml_huge_tree=True) self.client = ZeepClient(self._mantis_url, settings=settings) self.version = self.client.service.mc_version()
def wsdl(self, value): self.client = ZeepClient(value)
def get_report_parameters(client, report_path, context): zeep_client = ZeepClient(f"{client.base_url}{endpoint}") return zeep_client.service.GetReportParameters(report_path, context)
def get_report_list(client, context): zeep_client = ZeepClient(f"{client.base_url}{endpoint}") return zeep_client.service.GetReportList(context)