def _downloadFile(self, download_url): resp = None """ nasz ed jest tak genialny ze trzeba odczekac jakis czas od zalogowania zanim wysle sie request o export, dostaniemy niby 302 a potem z redirectu 200 ale contetnt-lenght = 0 czyli bez pliku #takbardzojanuszowate #2wieczorydebugowania""" time.sleep(5) for x in range(0, 10): try: resp = requests.get(download_url, verify=False, headers=self.headers) except ConnectionError as e: raise e if len(resp.content) > 0: break # odstep miedzy requestami. Moze ed jest kobieta i nie jest jeszcze "gotowy" :P time.sleep(5) self.csv_string = resp.content if len(self.csv_string ) == 0 or not self.csv_string.startswith('Temat'): raise ConnectionError('Cannot download schedule') if resp.ok: return StringIO.StringIO(self.csv_string) else: return None
def _login(self, post_url): post_data_dict = { 'formname': 'login', 'userid': self.user_login, 'password': self.user_password } try: resp = requests.post(post_url, data=post_data_dict, verify=False, headers=self.headers) except ConnectionError as e: raise e if len(resp.history) > 0: self.logged = True elif len(resp.history) == 0: # TODO change login verification method raise ConnectionError('Wrong Login/Password') else: raise ConnectionError("Can't login")
def put(self, *args, **kwargs): if any(ref in args[0] for ref in self.fail_on): raise ConnectionError( "Connection fails with lib2 and lib4 references!") else: return super(BadConnectionUploader, self).put(*args, **kwargs)
def put(self, *args, **kwargs): self.counter_fail += 1 if self.counter_fail % 2 == 1: raise ConnectionError("Pair file, error!") else: return super(BadConnectionUploader, self).put(*args, **kwargs)
def put(self, *args, **kwargs): raise ConnectionError("Can't connect because of the evil mock")
def put(self, *args, **kwargs): self.counter_fail += 1 if self.counter_fail == self.fail_on: raise ConnectionError("Can't connect because of the evil mock") else: return super(BadConnectionUploader, self).put(*args, **kwargs)