Python xmlrpclib.ProtocolError() Examples
The following are 30
code examples of xmlrpclib.ProtocolError().
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
xmlrpclib
, or try the search function
.
Example #1
Source File: opensubtitles.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def download_subtitle(self, subtitle): if self.server is None: # Nothing to do raise ProviderError('Provider not initialized.') try: response = self.server.DownloadSubtitles(self.token, [subtitle.id]) logger.debug('Download URL: %s {token=%s, subid:%s}' % ( self.server_url, self.token, subtitle.id, )) except xmlrpclib.ProtocolError: raise ProviderNotAvailable if response['status'] != '200 OK': raise ProviderError( 'Download failed with status %s' % str(response['status'])) if not response['data']: raise ProviderError('Nothing to download') subtitle_bytes = zlib.decompress(base64.b64decode(response['data'][0]['data']), 47) 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 #2
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_non_existing_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.this_is_not_exists() result = multicall() # result.results contains; # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<type \'exceptions.Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #3
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_basic(self): # check that flag is false by default flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header self.assertEqual(flagval, False) # enable traceback reporting SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True # test a call that shouldn't fail just as a smoke test try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #4
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_fail_with_info(self): # use the broken message class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # We should get error info in the response expected_err = "invalid literal for int() with base 10: 'I am broken'" self.assertEqual(e.headers.get("x-exception"), expected_err) self.assertTrue(e.headers.get("x-traceback") is not None)
Example #5
Source File: xmlrpclib2.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def _request(self, host, handler, request_body, verbose=0): # issue XML-RPC request h = self.cache.get_connection() try: self._set_connection_params(h) h.add_data(request_body) response = pycurllib.urlopen(h, close=False) except: # connection may no longer be valid self.cache.destroy_connection(h) raise self.cache.put_connection(h) if response.code != 200: raise xmlrpclib.ProtocolError( host + handler, response.code, response.msg, 'N/A', ) self.verbose = verbose return self._parse_response(response)
Example #6
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
def is_unavailable_exception(e): '''Returns True if the given ProtocolError is the product of a server-side exception caused by the 'temporarily unavailable' response sometimes given by operations on non-blocking sockets.''' # sometimes we get a -1 error code and/or empty headers try: if e.errcode == -1 or e.headers is None: return True exc_mess = e.headers.get('X-exception') except AttributeError: # Ignore socket.errors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True return False
Example #7
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.add(2,3) multicall.pow(6,8) multicall.div(127,42) add_result, pow_result, div_result = multicall() self.assertEqual(add_result, 2+3) self.assertEqual(pow_result, 6**8) self.assertEqual(div_result, 127//42) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #8
Source File: xmlrpclib2.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def _request(self, host, handler, request_body, verbose=0): # issue XML-RPC request h = self.cache.get_connection() try: self._set_connection_params(h) h.add_data(request_body) response = pycurllib.urlopen(h, close=False) except: # connection may no longer be valid self.cache.destroy_connection(h) raise self.cache.put_connection(h) if response.code != 200: raise xmlrpclib.ProtocolError( host + handler, response.code, response.msg, 'N/A', ) self.verbose = verbose return self._parse_response(response)
Example #9
Source File: test_xmlrpc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def is_unavailable_exception(e): '''Returns True if the given ProtocolError is the product of a server-side exception caused by the 'temporarily unavailable' response sometimes given by operations on non-blocking sockets.''' # sometimes we get a -1 error code and/or empty headers try: if e.errcode == -1 or e.headers is None: return True exc_mess = e.headers.get('X-exception') except AttributeError: # Ignore socket.errors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True return False
Example #10
Source File: requests_xmlrpclib.py From patzilla with GNU Affero General Public License v3.0 | 6 votes |
def request(self, host, handler, request_body, verbose): """ Make an xmlrpc request. """ client = self.session or requests headers = {'User-Agent': self.user_agent, 'Content-Type': 'text/xml', } url = self._build_url(host, handler) try: resp = client.post(url, data=request_body, headers=headers, timeout=self.timeout) except ValueError: raise except Exception: raise # something went wrong else: try: resp.raise_for_status() except requests.RequestException as e: raise xmlrpc.ProtocolError(url, resp.status_code, str(e), resp.headers) else: return self.parse_response(resp)
Example #11
Source File: test_xmlrpc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.add(2,3) multicall.pow(6,8) multicall.div(127,42) add_result, pow_result, div_result = multicall() self.assertEqual(add_result, 2+3) self.assertEqual(pow_result, 6**8) self.assertEqual(div_result, 127//42) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #12
Source File: test_xmlrpc.py From ironpython2 with Apache License 2.0 | 6 votes |
def is_unavailable_exception(e): '''Returns True if the given ProtocolError is the product of a server-side exception caused by the 'temporarily unavailable' response sometimes given by operations on non-blocking sockets.''' # sometimes we get a -1 error code and/or empty headers try: if e.errcode == -1 or e.headers is None: return True exc_mess = e.headers.get('X-exception') except AttributeError: # Ignore socket.errors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True return False
Example #13
Source File: test_xmlrpc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_non_existing_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.this_is_not_exists() result = multicall() # result.results contains; # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<type \'exceptions.Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #14
Source File: test_xmlrpc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def is_unavailable_exception(e): '''Returns True if the given ProtocolError is the product of a server-side exception caused by the 'temporarily unavailable' response sometimes given by operations on non-blocking sockets.''' # sometimes we get a -1 error code and/or empty headers try: if e.errcode == -1 or e.headers is None: return True exc_mess = e.headers.get('X-exception') except AttributeError: # Ignore socket.errors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True return False
Example #15
Source File: bitcoinclient.py From orisi with MIT License | 6 votes |
def bitcoind_get_transactions_from_block(self, block, addresses): logging.info(addresses) transaction_ids = block['tx'] transactions_per_address = {} for addr in addresses: transactions_per_address[addr] = [] for tx in transaction_ids: try: raw_transaction = self.get_raw_transaction(tx) except ProtocolError: continue transaction = self.decode_raw_transaction(raw_transaction) for vout in transaction['vout']: if not 'addresses' in vout['scriptPubKey']: continue addresses_in_vout = set(vout['scriptPubKey']['addresses']) for addr in addresses: if addr in addresses_in_vout: transactions_per_address[addr].append(transaction) logging.info(transactions_per_address) return transactions_per_address
Example #16
Source File: RemoteSwingLibrary.py From remoteswinglibrary with Apache License 2.0 | 6 votes |
def _run_and_ignore_connection_lost(self): try: yield except RuntimeError as r: # disconnection from remotelibrary if 'Connection to remote server broken:' in r.args[0]: logger.info('Connection died as expected') return raise except HandlerExecutionFailed as e: # disconnection from xmlrpc wrapped in robot keyword if any(elem in e.args[0] for elem in ('Connection to remote server broken:', 'ProtocolError')): logger.info('Connection died as expected') return raise except ProtocolError as r: # disconnection from xmlrpc in jython on some platforms logger.info('Connection died as expected') return
Example #17
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
def test_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.add(2,3) multicall.pow(6,8) multicall.div(127,42) add_result, pow_result, div_result = multicall() self.assertEqual(add_result, 2+3) self.assertEqual(pow_result, 6**8) self.assertEqual(div_result, 127//42) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #18
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
def test_non_existing_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.this_is_not_exists() result = multicall() # result.results contains; # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<type \'exceptions.Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #19
Source File: opensubtitles.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def terminate(self): if self.server is None: # Nothing to do return try: response = self.server.LogOut(self.token) except xmlrpclib.ProtocolError: raise ProviderNotAvailable except xmlrpclib.ResponseNotReady: logger.warning('ResponseNotReady exception thrown on logout.') return if response['status'] != '200 OK': raise ProviderError('Logout failed with status %r' % response['status'])
Example #20
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
def test_basic(self): # check that flag is false by default flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header self.assertEqual(flagval, False) # enable traceback reporting SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True # test a call that shouldn't fail just as a smoke test try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #21
Source File: test_xmlrpc.py From BinderFilter with MIT License | 6 votes |
def test_fail_with_info(self): # use the broken message class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # We should get error info in the response expected_err = "invalid literal for int() with base 10: 'I am broken'" self.assertEqual(e.headers.get("x-exception"), expected_err) self.assertTrue(e.headers.get("x-traceback") is not None)
Example #22
Source File: test_xmlrpc.py From oss-ftp with MIT License | 6 votes |
def is_unavailable_exception(e): '''Returns True if the given ProtocolError is the product of a server-side exception caused by the 'temporarily unavailable' response sometimes given by operations on non-blocking sockets.''' # sometimes we get a -1 error code and/or empty headers try: if e.errcode == -1 or e.headers is None: return True exc_mess = e.headers.get('X-exception') except AttributeError: # Ignore socket.errors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True return False
Example #23
Source File: test_xmlrpc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_fail_with_info(self): # use the broken message class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # We should get error info in the response expected_err = "invalid literal for int() with base 10: 'I am broken'" self.assertEqual(e.headers.get("x-exception"), expected_err) self.assertTrue(e.headers.get("x-traceback") is not None)
Example #24
Source File: test_xmlrpc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_basic(self): # check that flag is false by default flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header self.assertEqual(flagval, False) # enable traceback reporting SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True # test a call that shouldn't fail just as a smoke test try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #25
Source File: test_xmlrpc.py From oss-ftp with MIT License | 6 votes |
def test_fail_with_info(self): # use the broken message class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # We should get error info in the response expected_err = "invalid literal for int() with base 10: 'I am broken'" self.assertEqual(e.headers.get("x-exception"), expected_err) self.assertTrue(e.headers.get("x-traceback") is not None)
Example #26
Source File: test_xmlrpc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_non_existing_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.this_is_not_exists() result = multicall() # result.results contains; # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<type \'exceptions.Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #27
Source File: test_xmlrpc.py From oss-ftp with MIT License | 6 votes |
def test_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.add(2,3) multicall.pow(6,8) multicall.div(127,42) add_result, pow_result, div_result = multicall() self.assertEqual(add_result, 2+3) self.assertEqual(pow_result, 6**8) self.assertEqual(div_result, 127//42) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #28
Source File: test_xmlrpc.py From oss-ftp with MIT License | 6 votes |
def test_non_existing_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.this_is_not_exists() result = multicall() # result.results contains; # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<type \'exceptions.Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #29
Source File: test_xmlrpc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_multicall(self): try: p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.add(2,3) multicall.pow(6,8) multicall.div(127,42) add_result, pow_result, div_result = multicall() self.assertEqual(add_result, 2+3) self.assertEqual(pow_result, 6**8) self.assertEqual(div_result, 127//42) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
Example #30
Source File: test_xmlrpc.py From oss-ftp with MIT License | 6 votes |
def test_basic(self): # check that flag is false by default flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header self.assertEqual(flagval, False) # enable traceback reporting SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True # test a call that shouldn't fail just as a smoke test try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) except (xmlrpclib.ProtocolError, socket.error), e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", "")))