Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. # vim:fileencoding=utf-8
  2. from __future__ import absolute_import, division, unicode_literals
  3.  
  4. from logging import getLogger
  5.  
  6. from constance import config
  7. from requests.auth import HTTPBasicAuth
  8. from zeep import Client as SOAPClient
  9. from zeep.transports import Transport
  10.  
  11.  
  12. logger = getLogger(__name__)
  13.  
  14.  
  15. class SoapService(object):
  16.     transport = None
  17.     client = None
  18.  
  19.     def __init__(self):
  20.         self.transport = Transport(
  21.             http_auth=HTTPBasicAuth(
  22.                 username=config.ALLOINCOGNITO_BASIC_LOGIN_V2,
  23.                 password=config.ALLOINCOGNITO_BASIC_PASSWORD_V2,
  24.             ),
  25.             timeout=config.ALLOINCOGNITO_LOADER_TIMEOUT_V2,
  26.             verify=False
  27.         )
  28.         self.client = SOAPClient(
  29.             wsdl=config.ALLOINCOGNITO_WSDL_PATH_V2,
  30.             transport=self.transport
  31.         )
  32.  
  33.     def get_all_numbers(self):
  34.         i = 1
  35.         numbers = []
  36.         while True:
  37.             try:
  38.                 data = self.client.service.GetNumList(
  39.                     login=config.ALLOINCOGNITO_METHOD_LOGIN_V2,
  40.                     password=config.ALLOINCOGNITO_METHOD_PASSWORD_V2,
  41.                     pageSize=config.ALLOINCOGNITO_PAGE_SIZE,
  42.                     pageIndex=i
  43.                 )["Items"]["Num"]
  44.             except KeyError:
  45.                 raise Exception(u"Метод GetNumList вернул данные, имеющие не верный формат")
  46.  
  47.             if len(data) < 1:
  48.                 break
  49.             i += 1
  50.             numbers.append(data)
  51.         return numbers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement