Beispiel #1
0
 def get_url_with_papi_access(self, url, type, cookies=None, timeout=None, saveToDb=True):
     papiaccess = IndexerApiAccess(indexer=self.indexer, type=type, url=url, time=arrow.utcnow().datetime)
     try:
         papiaccess.username = request.authorization.username if request.authorization is not None else None
     except RuntimeError:
         #Is thrown when we're searching which is run in a thread. When downloading NFOs or whatever this will work
         pass
     indexerStatus = None
     try:
         time_before = arrow.utcnow()
         response = self.get(url, cookies=cookies, timeout=timeout)
         response.raise_for_status()
         time_after = arrow.utcnow()
         papiaccess.response_time = (time_after - time_before).seconds * 1000 + ((time_after - time_before).microseconds / 1000)
         papiaccess.response_successful = True
         indexerStatus = self.handle_indexer_success(saveIndexerStatus=saveToDb)
     except RequestException as e:
         self.error("Error while connecting to URL %s: %s" % (url, str(e)))
         papiaccess.error = "Connection failed: %s" % removeSensitiveData(str(e))
         response = None
         indexerStatus = self.handle_indexer_failure("Connection failed: %s" % removeSensitiveData(str(e)), saveIndexerStatus=saveToDb)
     finally:
         if saveToDb:
             papiaccess.save()
     return response, papiaccess, indexerStatus
Beispiel #2
0
 def get_url_with_papi_access(self, url, type, cookies=None, timeout=None, saveToDb=True):
     papiaccess = IndexerApiAccess(indexer=self.indexer, type=type, url=url, time=arrow.utcnow().datetime)
     try:
         papiaccess.username = request.authorization.username if request.authorization is not None else None
     except RuntimeError:
         #Is thrown when we're searching which is run in a thread. When downloading NFOs or whatever this will work
         pass
     indexerStatus = None
     try:
         time_before = arrow.utcnow()
         response = self.get(url, cookies=cookies, timeout=timeout)
         response.raise_for_status()
         time_after = arrow.utcnow()
         papiaccess.response_time = (time_after - time_before).seconds * 1000 + ((time_after - time_before).microseconds / 1000)
         papiaccess.response_successful = True
         indexerStatus = self.handle_indexer_success(saveIndexerStatus=saveToDb)
     except RequestException as e:
         self.logger.error("Error while connecting to URL %s: %s" % (url, str(e)))
         papiaccess.error = "Connection failed: %s" % removeSensitiveData(str(e))
         response = None
         indexerStatus = self.handle_indexer_failure("Connection failed: %s" % removeSensitiveData(str(e)), saveIndexerStatus=saveToDb)
     finally:
         if saveToDb:
             papiaccess.save()
     return response, papiaccess, indexerStatus