def _send(self, **kwargs): params = { 'login': kwargs['login'], 'psw': kwargs['password'], 'phones': kwargs['tel'], 'mes': kwargs['text'], 'fmt': 3, } try: resp = requests.get( url=self.gate_url_template + '?' + urllib.parse.urlencode(params) ) # raises exception in case of some conection/pool failure if re.search('^[45]', str(resp.status_code)): raise HTTPError(resp.status_code) # raises exception in case of 4xx or 5xx HTTP response json = resp.json() if 'error' in json: e = HTTPError( # raises exception if 200 OK but there is a problem in business logic '%s:\n%s' % ( self.error_descr.get(json['error_code']), json.get('error') ) ) e.sms_id = json.get('id') # supply the message id if any raise e else: return json['id'] except HTTPError as e: raise