Python xmlrpc.client.ProtocolError() Examples
The following are 30
code examples of xmlrpc.client.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
xmlrpc.client
, or try the search function
.
Example #1
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main 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, OSError) as 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 #2
Source File: test_xmlrpc.py From ironpython3 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 OSErrors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True
Example #3
Source File: test_xmlrpc.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_fail_with_info(self): # use the broken message class xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, OSError) as 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) else: self.fail('ProtocolError not raised')
Example #4
Source File: test_xmlrpc.py From Fluid-Designer 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, OSError) as 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 #5
Source File: subtitles.py From SubCrawl with MIT License | 6 votes |
def _download_file(self, proxy, subtitle_ids): """ Tries to download byte data. If successful the data will be stored to a table in the database. Afterwards, that same data will be taken from that table and another table and written to a file. """ download_data = dict() try: download_data = proxy.DownloadSubtitles(self.opensubs_token, subtitle_ids) except ProtocolError as e: download_data["status"] = e self.prompt_label.setText("There has been a ProtocolError during downloading") except ResponseNotReady as e: download_data["status"] = e self.prompt_label.setText("There has been a ResponseNotReady Error during downloading") if download_data["status"] == "200 OK": self._store_byte_data_to_db(download_data) self._get_stored_byte_data() else: self.prompt_label.setText("There was an error while trying to download your file: {}" .format(download_data["status"]))
Example #6
Source File: xmlrpc.py From gandi.cli with GNU General Public License v3.0 | 6 votes |
def request(self, host, handler, request_body, verbose): """ Make an xmlrpc request. """ headers = {'User-Agent': self.user_agent, 'Accept': 'text/xml', 'Content-Type': 'text/xml'} url = self._build_url(host, handler) try: resp = requests.post(url, data=request_body, headers=headers) except ValueError: raise except Exception: raise # something went wrong else: try: resp.raise_for_status() except requests.RequestException as e: raise xmlrpclib.ProtocolError(url, resp.status_code, str(e), resp.headers) else: return self.parse_response(resp)
Example #7
Source File: test_xmlrpc.py From Fluid-Designer 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 OSErrors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True
Example #8
Source File: test_xmlrpc.py From bazarr with GNU General Public License v3.0 | 6 votes |
def request(self, host, handler, request_body, verbose=0): # issue XML-RPC request h = self.make_connection(host) if verbose: h.set_debuglevel(1) self.send_request(h, handler, request_body) self.send_host(h, host) self.send_user_agent(h) self.send_content(h, request_body) errcode, errmsg, headers = h.getreply() if errcode != 200: raise ProtocolError(host + handler, errcode, errmsg, headers) self.verbose = verbose # Here's where we differ from the superclass. It says: # try: # sock = h._conn.sock # except AttributeError: # sock = None # return self._parse_response(h.getfile(), sock) return self.parse_response(h.getfile())
Example #9
Source File: test_xmlrpc.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def request(self, host, handler, request_body, verbose=0): # issue XML-RPC request h = self.make_connection(host) if verbose: h.set_debuglevel(1) self.send_request(h, handler, request_body) self.send_host(h, host) self.send_user_agent(h) self.send_content(h, request_body) errcode, errmsg, headers = h.getreply() if errcode != 200: raise ProtocolError(host + handler, errcode, errmsg, headers) self.verbose = verbose # Here's where we differ from the superclass. It says: # try: # sock = h._conn.sock # except AttributeError: # sock = None # return self._parse_response(h.getfile(), sock) return self.parse_response(h.getfile())
Example #10
Source File: web_profile_test_helpers.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def connect(self, pool_size=20, web_port=21012): """ Connect to the current SAMP Hub on localhost:web_port Parameters ---------- pool_size : int, optional The number of socket connections opened to communicate with the Hub. """ self._connected = False try: self.proxy = ServerProxyPool(pool_size, xmlrpc.ServerProxy, f'http://127.0.0.1:{web_port}', allow_none=1) self.ping() self._connected = True except xmlrpc.ProtocolError as p: raise SAMPHubError(f"Protocol Error {p.errcode}: {p.errmsg}")
Example #11
Source File: test_xmlrpc.py From Fluid-Designer 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': '<class \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<class \'Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, OSError) as 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_testrun.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_remove_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testruns.delete_testruntag') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestRun.remove_tag(self.test_runs[0].pk, self.tag0.name) # tags were not modified tag_exists = TestRun.objects.filter(pk=self.test_runs[0].pk, tag__pk=self.tag0.pk).exists() self.assertTrue(tag_exists) tag_exists = TestRun.objects.filter(pk=self.test_runs[0].pk, tag__pk=self.tag1.pk).exists() self.assertTrue(tag_exists)
Example #13
Source File: test_testrun.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_add_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testruns.add_testruntag') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestRun.add_tag(self.test_runs[0].pk, self.tag0.name) # tags were not modified tag_exists = TestRun.objects.filter(pk=self.test_runs[0].pk, tag__pk=self.tag0.pk).exists() self.assertFalse(tag_exists)
Example #14
Source File: test_testrun.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_remove_case_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testruns.delete_testexecution') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestRun.remove_case(self.test_run.pk, self.test_case.pk) exists = TestExecution.objects.filter(run=self.test_run.pk, case=self.test_case.pk).exists() self.assertTrue(exists)
Example #15
Source File: test_xmlrpc.py From ironpython3 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, OSError) as 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 #16
Source File: test_xmlrpc.py From ironpython3 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': '<class \'exceptions.Exception\'>:' # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) self.assertEqual(result.results[0]['faultString'], '<class \'Exception\'>:method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, OSError) as 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 #17
Source File: test_testplan.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_remove_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testplans.delete_testplantag') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestPlan.remove_tag(self.plans[0].pk, self.tag0.name) # tags were not modified tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag0.pk).exists() self.assertTrue(tag_exists) tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag1.pk).exists() self.assertFalse(tag_exists)
Example #18
Source File: test_xmlrpc.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_fail_with_info(self): # use the broken message class xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, OSError) as 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) else: self.fail('ProtocolError not raised')
Example #19
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 #20
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 #21
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main 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 OSErrors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): return True
Example #22
Source File: test_testplan.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_add_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testplans.add_testplantag') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestPlan.add_tag(self.plans[0].pk, self.tag1.name) # tags were not modified tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag1.pk).exists() self.assertFalse(tag_exists)
Example #23
Source File: test_testcase.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_remove_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testcases.delete_testcasetag') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestCase.remove_tag(self.testcase.pk, self.tag0.name) # tags were not modified tag_exists = TestCase.objects.filter(pk=self.testcase.pk, tag__pk=self.tag0.pk).exists() self.assertTrue(tag_exists) tag_exists = TestCase.objects.filter(pk=self.testcase.pk, tag__pk=self.tag1.pk).exists() self.assertFalse(tag_exists)
Example #24
Source File: test_testcase.py From Kiwi with GNU General Public License v2.0 | 6 votes |
def test_add_tag_without_permissions(self): unauthorized_user = UserFactory() unauthorized_user.set_password('api-testing') unauthorized_user.save() unauthorized_user.user_permissions.add(*Permission.objects.all()) remove_perm_from_user(unauthorized_user, 'testcases.add_testcasetag') rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username, 'api-testing', '%s/xml-rpc/' % self.live_server_url).server with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): rpc_client.TestCase.add_tag(self.testcase.pk, self.tag1.name) # tags were not modified tag_exists = TestCase.objects.filter(pk=self.testcase.pk, tag__pk=self.tag1.pk).exists() self.assertFalse(tag_exists)
Example #25
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_fail_with_info(self): # use the broken message class xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass # Check that errors in the server send back exception/traceback # info when flag is set xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, OSError) as 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) else: self.fail('ProtocolError not raised')
Example #26
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_basic(self): # check that flag is false by default flagval = xmlrpc.server.SimpleXMLRPCServer._send_traceback_header self.assertEqual(flagval, False) # enable traceback reporting xmlrpc.server.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, OSError) as 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: serializers.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def update(self, instance, validated_data): """Update a Provider instance from validated data.""" billing_source = validated_data.get("billing_source") authentication = validated_data.get("authentication") try: with ServerProxy(SOURCES_CLIENT_BASE_URL) as sources_client: if billing_source: billing_source = self._update_billing_source(instance, billing_source) sources_client.update_billing_source(instance.source_id, billing_source) if authentication: authentication = self._update_authentication(instance, authentication) sources_client.update_authentication(instance.source_id, authentication) except Fault as error: LOG.error(f"Sources update error: {error}") raise SourcesStorageError(str(error)) except (ConnectionRefusedError, gaierror, ProtocolError) as error: LOG.error(f"Sources update dependency error: {error}") raise SourcesDependencyError(f"Sources-client: {error}") return get_source_instance(instance.source_id)
Example #28
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_bad_gzip_request(self): t = self.Transport() t.encode_threshold = None t.fake_gzip = True p = xmlrpclib.ServerProxy(URL, transport=t) cm = self.assertRaisesRegex(xmlrpclib.ProtocolError, re.compile(r"\b400\b")) with cm: p.pow(6, 8) p("close")()
Example #29
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_fail_no_info(self): # use the broken message class xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # The two server-side error headers shouldn't be sent back in this case self.assertTrue(e.headers.get("X-exception") is None) self.assertTrue(e.headers.get("X-traceback") is None) else: self.fail('ProtocolError not raised')
Example #30
Source File: test_xmlrpc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_server_encoding(self): start_string = '\u20ac' end_string = '\xa4' try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.add(start_string, end_string), start_string + end_string) except (xmlrpclib.ProtocolError, socket.error) as 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", "")))