def login(self, username, password): """Log in to Betfair. Sets `session_token` if successful. :param str username: Username :param str password: Password :raises: BetfairLoginError """ response = self.session.post( os.path.join(self.identity_url, 'certlogin'), cert=self.cert_file, data=urllib.urlencode({ 'username': username, 'password': password, }), headers={ 'X-Application': self.app_key, 'Content-Type': 'application/x-www-form-urlencoded', }, timeout=self.timeout, ) utils.check_status_code(response, [httplib.OK]) data = response.json() if data.get('loginStatus') != 'SUCCESS': raise exceptions.LoginError(response, data) self.session_token = data['sessionToken']
def make_auth_request(self, method): response = self.session.post( os.path.join(self.identity_url, method), headers=self.headers, timeout=self.timeout, ) utils.check_status_code(response) data = response.json() if data.get('status') != 'SUCCESS': raise exceptions.AuthError(response, data)
def make_api_request(self, base, method, params, codes=None, model=None): payload = utils.make_payload(base, method, params) response = self.session.post( self.api_url, data=json.dumps(payload, cls=utils.BetfairEncoder), headers=self.headers, timeout=self.timeout, ) utils.check_status_code(response, codes=codes) result = utils.result_or_error(response) return utils.process_result(result, model)
def make_api_request(self, base, method, params, codes=None, model=None, url=None): payload = utils.make_payload(base, method, params) response = self.session.post( url if url else self.api_url, data=json.dumps(payload, cls=utils.BetfairEncoder), headers=self.headers, timeout=self.timeout, ) utils.check_status_code(response, codes=codes) result = utils.result_or_error(response) return utils.process_result(result, model)
def make_api_request(self, base, method, params, codes=None, model=None, url=None): payload = utils.make_payload(base, method, params) # print utils.model_to_dict(payload) response = self.session.post( url if url else self.api_url, data=json.dumps(payload, cls=utils.BetfairEncoder), headers=self.headers, timeout=self.timeout, ) utils.check_status_code(response, codes=codes) result = utils.result_or_error(response) # print json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(',', ': ')) return utils.process_result(result, model)
def make_api_request(self, base, method, params, codes=None, model=None): payload = utils.make_payload(base, method, params) if base=="Sports": api_url = self.betting_api_url else: api_url = self.account_api_url data = json.dumps(payload, cls=utils.BetfairEncoder) print("Data: {}".format(data)) response = self.session.post( api_url, data=data, headers=self.headers, timeout=self.timeout, ) # print(response.json()) utils.check_status_code(response, codes=codes) result = utils.result_or_error(response) processed_result = utils.process_result(result, model) return processed_result