Ejemplo n.º 1
0
 def __enter__(self):
     if None in [self.username, self._password, self.steam_guard]:
         raise InvalidCredentials(
             'You have to pass username, password and steam_guard'
             'parameters when using "with" statement')
     self.login(self.username, self._password, self.steam_guard)
     return self
Ejemplo n.º 2
0
 def api_call(self,
              request_method: str,
              interface: str,
              api_method: str,
              version: str,
              params: dict = None) -> requests.Response:
     url = '/'.join([self.API_URL, interface, api_method, version])
     attempts = 0
     response = None
     while attempts < 3:
         try:
             if request_method == 'GET':
                 response = requests.get(url, params=params,
                                         timeout=60).json()
             else:
                 response = requests.post(url, data=params,
                                          timeout=60).json()
             break
         except json.decoder.JSONDecodeError as err:
             print(err)
         attempts += 1
     if not response:
         raise Exception('The API server is unreachable')
     if self.is_invalid_api_key(response):
         raise InvalidCredentials('Invalid API key')
     return response
Ejemplo n.º 3
0
 def _fetch_confirmations_page(self) -> requests.Response:
     tag = Tag.CONF.value
     params = self._create_confirmation_params(tag)
     headers = {'X-Requested-With': 'com.valvesoftware.android.steam.community'}
     response = self._session.get(self.CONF_URL + '/conf', params=params, headers=headers)
     if 'Steam Guard Mobile Authenticator is providing incorrect Steam Guard codes.' in response.text:
         raise InvalidCredentials('Invalid Steam Guard file')
     return response
Ejemplo n.º 4
0
 def api_call(self, request_method: str, interface: str, api_method: str, version: str,
              params: dict = None) -> requests.Response:
     url = '/'.join([SteamUrl.API_URL, interface, api_method, version])
     if request_method == 'GET':
         response = requests.get(url, params=params)
     else:
         response = requests.post(url, data=params)
     if self.is_invalid_api_key(response):
         raise InvalidCredentials('Invalid API key')
     return response
Ejemplo n.º 5
0
 def _fetch_confirmations_page(self) -> requests.Response:
     tag = Tag.CONF.value
     params = self._create_confirmation_params(tag)
     headers = {
         'X-Requested-With': 'com.valvesoftware.android.steam.community'
     }
     response = self._session.get(self.CONF_URL + '/conf',
                                  params=params,
                                  headers=headers)
     if any(error_str in response.text
            for error_str in self.BAD_GUARD_FILE_MESSAGES):
         raise InvalidCredentials('Invalid Steam Guard file')
     return response
Ejemplo n.º 6
0
 def _fetch_confirmations_page(self) -> requests.Response:
     tag = Tag.CONF.value
     # 获取
     params = self._create_confirmation_params(tag)
     # 请求头
     headers = {
         "X-Requested-With": "com.valvesoftware.android.steam.community"
     }
     response = self._session.get(self.CONF_URL + "/conf",
                                  params=params,
                                  headers=headers)
     # 访问出错的情况
     if (("Steam Guard Mobile Authenticator is providing incorrect " \
             + "Steam Guard codes.") in response.text):
         raise InvalidCredentials("Invalid Steam Guard file")
     return response
Ejemplo n.º 7
0
 def _fetch_confirmations_page(self) -> requests.Response:
     tag = Tag.CONF.value
     params = self._create_confirmation_params(tag)
     headers = {
         'X-Requested-With': 'com.valvesoftware.android.steam.community'
     }
     response = self._session.get(self.CONF_URL + '/conf',
                                  params=params,
                                  headers=headers,
                                  timeout=60)
     if 'Steam Guard Mobile Authenticator is providing incorrect Steam Guard codes.' in response.text:
         raise InvalidCredentials('Invalid Steam Guard file')
     elif "You've made too many requests recently." in response.text:
         print('too many attempts made recently, waiting for 10 minutes')
         time.sleep(600)
     return response
Ejemplo n.º 8
0
    async def api_call(self,
                       url: URL,
                       params: dict = None,
                       post: bool = False) -> dict:
        if post:
            response = await self._api_session.post(url, data=params)
        else:
            response = await self._api_session.get(url, params=params)

        if response.status == 200:
            return await response.json()

        response_text = await response.text()
        if response.status == 403 and self._is_invalid_api_key(response_text):
            raise InvalidCredentials('Invalid API key')
        else:
            raise Exception(response_text)