コード例 #1
0
 def _request(self, method, component, session_refreshed, **kwargs):
     endpoint_conf = ENDPOINTS[component]
     url = (_api_url(endpoint_conf['address'])
            if endpoint_conf['is_api_call'] else _document_url(
                endpoint_conf['address']))
     common.debug('Executing {verb} request to {url}',
                  verb='GET' if method == self.session.get else 'POST',
                  url=url)
     data, headers, params = self._prepare_request_properties(
         endpoint_conf, kwargs)
     start = common.perf_clock()
     response = method(url=url,
                       verify=self.verify_ssl,
                       headers=headers,
                       params=params,
                       data=data)
     common.debug('Request took {}s', common.perf_clock() - start)
     common.debug('Request returned statuscode {}', response.status_code)
     if response.status_code in [404, 401] and not session_refreshed:
         # 404 - It may happen when Netflix update the build_identifier version and causes the api address to change
         # 401 - It may happen when authURL is not more valid (Unauthorized for url)
         # So let's try refreshing the session data (just once)
         common.warn('Try refresh session data due to {} http error',
                     response.status_code)
         if self.try_refresh_session_data():
             return self._request(method, component, True, **kwargs)
     response.raise_for_status()
     return (_raise_api_error(response.json() if response.content else {})
             if endpoint_conf['is_api_call'] else response.content)
コード例 #2
0
 def _post(self, endpoint, request_data):
     """Execute a post request"""
     common.debug('Executing POST request to {}', endpoint)
     start = common.perf_clock()
     response = self.session.post(endpoint, request_data)
     common.debug('Request took {}s', common.perf_clock() - start)
     common.debug('Request returned response with status {}', response.status_code)
     response.raise_for_status()
     return response
コード例 #3
0
 def _request(self, method, endpoint, session_refreshed, **kwargs):
     endpoint_conf = ENDPOINTS[endpoint]
     url = (_api_url(endpoint_conf['address'])
            if endpoint_conf['is_api_call'] else _document_url(
                endpoint_conf['address'], kwargs))
     common.debug('Executing {verb} request to {url}',
                  verb='GET' if method == self.session.get else 'POST',
                  url=url)
     data, headers, params = self._prepare_request_properties(
         endpoint_conf, kwargs)
     start = common.perf_clock()
     response = method(url=url,
                       verify=self.verify_ssl,
                       headers=headers,
                       params=params,
                       data=data)
     common.debug('Request took {}s', common.perf_clock() - start)
     common.debug('Request returned statuscode {}', response.status_code)
     if response.status_code in [404, 401] and not session_refreshed:
         # 404 - It may happen when Netflix update the build_identifier version and causes the api address to change
         # 401 - It may happen when authURL is not more valid (Unauthorized for url)
         # So let's try refreshing the session data (just once)
         common.warn('Try refresh session data due to {} http error',
                     response.status_code)
         if self.try_refresh_session_data():
             return self._request(method, endpoint, True, **kwargs)
     if response.status_code == 401:
         # 30/04/2020: first signal of http error 401 issues
         # After the profile selection sometime can happen the http error 401 Client Error: Unauthorized for url ...
         # due to the failure of the first shakti API request.
         # After a revision of the code of initial access, i have not found any reason that could cause this problem,
         # i am beginning to suspect that is a problem of the netflix service.
         # Not found any solutions, two http attempts are already made, so notify the user of the problem.
         # 02/05/2020: i intercepted this problem even browsing several times the lists,
         #             does not happen often, so the problem is more complex.
         common.error(
             'Raise error due to too many http error 401 (known error currently unresolvable)'
         )
         raise HttpError401
     response.raise_for_status()
     return (_raise_api_error(response.json() if response.content else {})
             if endpoint_conf['is_api_call'] else response.content)