当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.AuthException方法代码示例

本文整理汇总了Python中pgoapi.exceptions.AuthException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.AuthException方法的具体用法?Python exceptions.AuthException怎么用?Python exceptions.AuthException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pgoapi.exceptions的用法示例。


在下文中一共展示了exceptions.AuthException方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def start(self):
		self.login()

		while True:
			try:
				self.spin_fort()
				self.check_farming()
				if not self.farming_mode:
					self.snipe_pokemon()
					self.check_awarded_badges()
					self.inventorys.check_pokemons()

				self.check_limit()

			except (AuthException, NotLoggedInException, ServerSideRequestThrottlingException, TypeError, KeyError) as e:
				self.logger.error(e)
				self.logger.info(
					'Token Expired, wait for 20 seconds.'
				)
				time.sleep(20)
				self.login()
				continue 
开发者ID:PokemonAlpha,项目名称:AlphaBot,代码行数:24,代码来源:__init__.py

示例2: user_login

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def user_login(self, username, password):
        self.log.info('Google User Login for: {}'.format(username))

        if not isinstance(username, six.string_types) or not isinstance(password, six.string_types):
            raise AuthException("Username/password not correctly specified")

        user_login = perform_master_login(username, password, self.GOOGLE_LOGIN_ANDROID_ID)
        
        refresh_token = user_login.get('Token', None)
        if refresh_token is not None:
            self._refresh_token = refresh_token
            self.log.info('Google User Login successful.')
        else:
            self._refresh_token = None
            raise AuthException("Invalid Google Username/password")

        self.get_access_token() 
开发者ID:joaoanes,项目名称:pokescan,代码行数:19,代码来源:auth_google.py

示例3: set_authentication

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def set_authentication(self, provider = None, oauth2_refresh_token = None, username = None, password = None):
        if provider == 'ptc':
            self._auth_provider = AuthPtc()
        elif provider == 'google':
            self._auth_provider = AuthGoogle()
        elif provider is None:
            self._auth_provider = None
        else:
            raise AuthException("Invalid authentication provider - only ptc/google available.")

        self.log.debug('Auth provider: %s', provider)

        if oauth2_refresh_token is not None:
            self._auth_provider.set_refresh_token(oauth2_refresh_token)
        elif username is not None and password is not None:
            self._auth_provider.user_login(username, password)
        else:
            raise AuthException("Invalid Credential Input - Please provide username/password or an oauth2 refresh token") 
开发者ID:joaoanes,项目名称:pokescan,代码行数:20,代码来源:pgoapi.py

示例4: api_init

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def api_init(account):
    api = PGoApi()
    
    try:
        api.set_position(360,360,0)  
        api.set_authentication(provider = account.auth_service,\
                               username = account.username, password =  account.password)
        api.activate_signature(get_encryption_lib_path()); time.sleep(1); api.get_player()
    
    except AuthException:
        log.error('Login for %s:%s failed - wrong credentials?' % (account.username, account.password))
        return None
    
    else:
        time.sleep(1); response = api.get_inventory()
        
        if response:
            if 'status_code' in response:
                if response['status_code'] == 1 or response['status_code'] == 2: return api
                
                elif response['status_code'] == 3:
                    # try to accept ToS
                    time.sleep(5); response = api.mark_tutorial_complete(tutorials_completed = 0,\
                                    send_marketing_emails = False, send_push_notifications = False)                    

                    if response['status_code'] == 1 or response['status_code'] == 2:
                        print('Accepted TOS for %s' % account.username)
                        return api
                    
                    elif response['status_code'] == 3:
                        print('Account %s BANNED!' % account.username)
                        raise AccountBannedException; return None
                
    return None 
开发者ID:tcmaps,项目名称:fastmap,代码行数:36,代码来源:apiwrap.py

示例5: acceptTos

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def acceptTos(username, password, pos):
	api = PGoApi()
	api.set_position(pos[0], pos[1], 0.0)

	retryCount = 0
	while True:
		try:
			api.login('ptc', username, password)
			break
		except AuthException, NotLoggedInException:
			time.sleep(0.15)
			if retryCount > 3:
				return False
			retryCount += 1
		except ServerSideRequestThrottlingException:
			time.sleep(requestSleepTimer)
			if requestSleepTimer == 5.1:
				logQueue.put(click.style('[TOS accepter] Received slow down warning. Using max delay of 5.1 already.', fg='red', bold=True))
			else:
				logQueue.put(click.style('[TOS accepter] Received slow down warning. Increasing delay from %d to %d.' % (requestSleepTimer, requestSleepTimer+0.2), fg='red', bold=True))
				requestSleepTimer += 0.2

	time.sleep(2)
	req = api.create_request()
	req.mark_tutorial_complete(tutorials_completed = 0, send_marketing_emails = False, send_push_notifications = False)
	response = req.call()
	if type(response) == dict and response['status_code'] == 1 and response['responses']['MARK_TUTORIAL_COMPLETE']['success'] == True:
		return True
	return False 
开发者ID:diksm8,项目名称:pGo-create,代码行数:31,代码来源:pgocreate.py

示例6: user_login

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def user_login(self, username, password):
        self.log.info('PTC User Login for: {}'.format(username))

        if not isinstance(username, six.string_types) or not isinstance(password, six.string_types):
            raise AuthException("Username/password not correctly specified")
        
        head = {'User-Agent': 'niantic'}
        r = self._session.get(self.PTC_LOGIN_URL, headers=head)

        try:
            jdata = json.loads(r.content.decode('utf-8'))
            data = {
                'lt': jdata['lt'],
                'execution': jdata['execution'],
                '_eventId': 'submit',
                'username': username,
                'password': password,
            }
        except ValueError as e:
            self.log.error('PTC User Login Error - Field missing in response: %s', e)
            return False
        except KeyError as e:
            self.log.error('PTC User Login Error - Field missing in response.content: %s', e)
            return False

        r1 = self._session.post(self.PTC_LOGIN_URL, data=data, headers=head)

        ticket = None
        try:
            ticket = re.sub('.*ticket=', '', r1.history[0].headers['Location'])
        except Exception as e:
            try:
                self.log.error('Could not retrieve token: %s', r1.json()['errors'][0])
            except Exception as e:
                self.log.error('Could not retrieve token! (%s)', e)
            return False

        self._refresh_token = ticket
        self.log.info('PTC User Login successful.')

        self.get_access_token() 
开发者ID:joaoanes,项目名称:pokescan,代码行数:43,代码来源:auth_ptc.py

示例7: get_access_token

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def get_access_token(self, force_refresh = False):
        token_validity = self.check_access_token()

        if token_validity is True and force_refresh is False:
            self.log.debug('Using cached Google Access Token')
            return self._access_token
        else:
            if force_refresh:
                self.log.info('Forced request of Google Access Token!')
            else:
                self.log.info('Request Google Access Token...')

            token_data = perform_oauth(None, self._refresh_token, self.GOOGLE_LOGIN_ANDROID_ID, self.GOOGLE_LOGIN_SERVICE, self.GOOGLE_LOGIN_APP,
                self.GOOGLE_LOGIN_CLIENT_SIG)

            access_token = token_data.get('Auth', None)
            if access_token is not None:
                self._access_token = access_token
                self._access_token_expiry = int(token_data.get('Expiry', 0))
                self._login = True

                self.log.info('Google Access Token successfully received.')
                self.log.debug('Google Access Token: %s...', self._access_token[:25])
            else:
                self._access_token = None
                self._login = False
                raise AuthException("Could not receive a Google Access Token") 
开发者ID:joaoanes,项目名称:pokescan,代码行数:29,代码来源:auth_google.py

示例8: api_init

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def api_init(account):
    api = PGoApi()
    
    try:
        api.set_position(360,360,0)  
        api.set_authentication(provider = account.auth_service,
                               username = account.username, password =  account.password)
        api.activate_signature(get_encryption_lib_path()); time.sleep(1); api.get_player()
    
    except AuthException:
        log.error('Login for %s:%s failed - wrong credentials?' % (account.username, account.password))
        return None
    
    else:
        time.sleep(1); response = api.get_inventory()
        
        if response:
            if 'status_code' in response:
                if response['status_code'] == 1 or response['status_code'] == 2: return api
                
                elif response['status_code'] == 3:
                    # try to accept ToS
                    time.sleep(5); response = api.mark_tutorial_complete(tutorials_completed = 0,
                                    send_marketing_emails = False, send_push_notifications = False)                    

                    if response['status_code'] == 1 or response['status_code'] == 2:
                        print('Accepted TOS for %s' % account.username)
                        return api
                    
                    elif response['status_code'] == 3:
                        print('Account %s BANNED!' % account.username)
                        raise AccountBannedException
                
    return None 
开发者ID:tcmaps,项目名称:pickymap,代码行数:36,代码来源:ext.py

示例9: get_access_token

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def get_access_token(self, force_refresh = False):
        token_validity = self.check_access_token()

        if token_validity is True and force_refresh is False:
            self.log.debug('Using cached PTC Access Token')
            return self._access_token
        else:
            if force_refresh:
                self.log.info('Forced request of PTC Access Token!')
            else:
                self.log.info('Request PTC Access Token...')

            data1 = {
                'client_id': 'mobile-app_pokemon-go',
                'redirect_uri': 'https://www.nianticlabs.com/pokemongo/error',
                'client_secret': self.PTC_LOGIN_CLIENT_SECRET,
                'grant_type': 'refresh_token',
                'code': self._refresh_token,
            }
            
            r2 = self._session.post(self.PTC_LOGIN_OAUTH, data=data1)

            qs = r2.content.decode('utf-8')
            token_data = parse_qs(qs)
            
            access_token = token_data.get('access_token', None)
            if access_token is not None:
                self._access_token = access_token[0]

                now_s = get_time()
                expires = int(token_data.get('expires', [0])[0])
                if expires > 0:
                    self._access_token_expiry = expires + now_s
                else:
                    self._access_token_expiry = 0

                self._login = True

                self.log.info('PTC Access Token successfully retrieved.')
                self.log.debug('PTC Access Token: %s...', self._access_token[:25])
            else:
                self._access_token = None
                self._login = False
                raise AuthException("Could not retrieve a PTC Access Token") 
开发者ID:joaoanes,项目名称:pokescan,代码行数:46,代码来源:auth_ptc.py

示例10: run

# 需要导入模块: from pgoapi import exceptions [as 别名]
# 或者: from pgoapi.exceptions import AuthException [as 别名]
def run(self):
        self.log_info("Waiting for job...")
        while True:
            (prio, t, job) = self.job_queue.get()
            try:
                if job.expired():
                    self.log_warning(
                        u"Scout job for {} at {}, {} expired. Rejecting.".format(job.pokemon_name, job.lat, job.lng))
                    job.result = self.scout_error(self.last_msg)
                    continue

                self.log_info(u"Scouting a {} at {}, {} with {} priority".format(job.pokemon_name, job.lat, job.lng,
                                                                                 PRIO_NAMES[prio]))

                # Initialize API
                (lat, lng) = jitter_location(job.lat, job.lng)
                self.set_position(lat, lng, job.altitude)
                if not self.check_login():
                    job.result = self.scout_error(self.last_msg)
                    if self.is_banned() or self.has_captcha():
                        break
                    else:
                        continue

                if job.encounter_id and job.spawn_point_id:
                    job.result = self.scout_by_encounter_id(job)
                else:
                    if self.find_pokemon(job):
                        time.sleep(2)
                        job.result = self.scout_by_encounter_id(job)
                    else:
                        job.result = self.scout_error("Could not determine encounter_id for {} at {}, {}".format(job.pokemon_name, job.lat, job.lng))

                # Mark shadowbanned if too many errors
                sb_threshold = cfg_get('shadowban_threshold')
                if sb_threshold and self.errors >= sb_threshold:
                    self.shadowbanned = True

                if self.shadowbanned:
                    self.log_warning("Account probably shadowbanned. Stopping.")
                    break

            except (AuthException, BannedAccountException, CaptchaException) as e:
                job.result = self.scout_error(self.last_msg)
                break
            except Exception:
                job.result = self.scout_error(repr(sys.exc_info()))
            finally:
                job.processed = True
                if self.is_banned() or self.has_captcha():
                    break 
开发者ID:sLoPPydrive,项目名称:PGScout,代码行数:53,代码来源:Scout.py


注:本文中的pgoapi.exceptions.AuthException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。