예제 #1
0
    def LoginHF(self, network_context):

        session = self.engine.session_manager.GetSession(network_context)

        num_attempts = 0

        while True:

            try:

                response = session.get('https://www.hentai-foundry.com/',
                                       timeout=10)

                break

            except requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout:

                if num_attempts < 3:

                    num_attempts += 1

                    time.sleep(3)

                else:

                    raise HydrusExceptions.ConnectionException(
                        'Could not connect to HF to log in!')
예제 #2
0
    def LoginHF(self, network_context):

        session = self.engine.session_manager.GetSession(network_context)

        num_attempts = 0

        while True:

            try:

                response = session.get('https://www.hentai-foundry.com/',
                                       timeout=10)

                break

            except (requests.exceptions.ConnectionError,
                    requests.exceptions.ConnectTimeout):

                if num_attempts < 3:

                    num_attempts += 1

                    time.sleep(3)

                else:

                    raise HydrusExceptions.ConnectionException(
                        'Could not connect to HF to log in!')

        time.sleep(1)

        response = session.get('https://www.hentai-foundry.com/?enterAgree=1')

        time.sleep(1)

        cookie_dict = self._GetCookiesDict(network_context)

        raw_csrf = cookie_dict[
            'YII_CSRF_TOKEN']  # 19b05b536885ec60b8b37650a32f8deb11c08cd1s%3A40%3A%222917dcfbfbf2eda2c1fbe43f4d4c4ec4b6902b32%22%3B

        processed_csrf = urllib.unquote(
            raw_csrf
        )  # 19b05b536885ec60b8b37650a32f8deb11c08cd1s:40:"2917dcfbfbf2eda2c1fbe43f4d4c4ec4b6902b32";

        csrf_token = processed_csrf.split('"')[1]  # the 2917... bit

        hentai_foundry_form_info = ClientDefaults.GetDefaultHentaiFoundryInfo()

        hentai_foundry_form_info['YII_CSRF_TOKEN'] = csrf_token

        response = session.post('http://www.hentai-foundry.com/site/filters',
                                data=hentai_foundry_form_info)

        time.sleep(1)
예제 #3
0
    def Start(self):

        try:

            request_completed = False

            while not request_completed:

                try:

                    response = self._SendRequestAndGetResponse()

                    with self._lock:

                        if self._body is not None:

                            self._ReportDataUsed(len(self._body))

                    if 'Content-Type' in response.headers:

                        self._content_type = response.headers['Content-Type']

                    if response.ok:

                        with self._lock:

                            self._status_text = u'downloading\u2026'

                        if self._temp_path is None:

                            self._ReadResponse(response, self._stream_io,
                                               104857600)

                        else:

                            with open(self._temp_path, 'wb') as f:

                                self._ReadResponse(response, f)

                        with self._lock:

                            self._status_text = 'done!'

                    else:

                        with self._lock:

                            self._status_text = str(
                                response.status_code) + ' - ' + str(
                                    response.reason)

                        self._ReadResponse(response, self._stream_io,
                                           104857600)

                        with self._lock:

                            self._stream_io.seek(0)

                            data = self._stream_io.read()

                            (e, error_text
                             ) = ConvertStatusCodeAndDataIntoExceptionInfo(
                                 response.status_code, data,
                                 self.IS_HYDRUS_SERVICE)

                            self._SetError(e, error_text)

                    request_completed = True

                except HydrusExceptions.ShouldReattemptNetworkException as e:

                    self._current_connection_attempt_number += 1

                    if not self._CanReattemptRequest():

                        raise HydrusExceptions.NetworkException(
                            'Ran out of reattempts on this error: ' +
                            HydrusData.ToUnicode(e))

                    with self._lock:

                        self._status_text = HydrusData.ToUnicode(
                            e) + '--retrying'

                    time.sleep(3)

                except requests.exceptions.ChunkedEncodingError:

                    self._current_connection_attempt_number += 1

                    if not self._CanReattemptRequest():

                        raise HydrusExceptions.ConnectionException(
                            'Unable to complete request--it broke mid-way!')

                    with self._lock:

                        self._status_text = u'connection broke mid-request--retrying'

                    time.sleep(3)

                except (requests.exceptions.ConnectionError,
                        requests.exceptions.ConnectTimeout):

                    self._current_connection_attempt_number += 1

                    if not self._CanReattemptConnection():

                        raise HydrusExceptions.ConnectionException(
                            'Could not connect!')

                    with self._lock:

                        self._status_text = u'connection failed--retrying'

                    time.sleep(3)

                except requests.exceptions.ReadTimeout:

                    self._current_connection_attempt_number += 1

                    if not self._CanReattemptRequest():

                        raise HydrusExceptions.ConnectionException(
                            'Connection successful, but reading response timed out!'
                        )

                    with self._lock:

                        self._status_text = u'read timed out--retrying'

                    time.sleep(3)

        except Exception as e:

            with self._lock:

                self._status_text = 'unexpected error!'

                trace = traceback.format_exc()

                HydrusData.Print(trace)

                self._SetError(e, trace)

        finally:

            with self._lock:

                self._SetDone()