Here are the examples of the python api requests.exceptions.SSLError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
58 Examples
3
View Complete Implementation : views.py
Copyright MIT License
Author : ahmadfaizalbh
Copyright MIT License
Author : ahmadfaizalbh
def who_is(query, sessionID="general"):
try:
return wikipedia.summary(query)
except requests.exceptions.SSLError:
return "Sorry I could not search online due to SSL error"
except:
past
for new_query in wikipedia.search(query):
try:
return wikipedia.summary(new_query)
except:
past
return "Sorry I could not find any data related to '%s'" % query
3
View Complete Implementation : test_duo.py
Copyright Apache License 2.0
Author : airbnb
Copyright Apache License 2.0
Author : airbnb
@patch('requests.get')
@patch('logging.Logger.exception')
def test_gather_logs_bad_response(self, log_mock, requests_mock):
"""DuoApp - Gather Logs, Bad Response"""
requests_mock.side_effect = requests.exceptions.SSLError(None, request='Bad')
astert_false(self._app._gather_logs())
log_mock.astert_called_with('Received bad response from duo')
3
View Complete Implementation : auth_code.py
Copyright Apache License 2.0
Author : amikey
Copyright Apache License 2.0
Author : amikey
def download_code(self):
url = API_AUTH_CODE_BASE64_DOWNLOAD.format(random=random.random())
# code_path = self.data_path + 'code.png'
try:
UserLog.add_quick_log(UserLog.MESSAGE_DOWNLAODING_THE_CODE).flush()
# response = self.session.save_to_file(url, code_path) # TODO 返回错误情况
response = self.session.get(url)
result = response.json()
if result.get('image'):
return result.get('image')
raise SSLError('返回数据为空')
except SSLError as e:
UserLog.add_quick_log(
UserLog.MESSAGE_DOWNLAOD_AUTH_CODE_FAIL.format(e, self.retry_time)).flush()
time.sleep(self.retry_time)
return self.download_code()
3
View Complete Implementation : test_rest_api.py
Copyright GNU General Public License v3.0
Author : ansible
Copyright GNU General Public License v3.0
Author : ansible
def test_galaxy_api_publish_file_request_error(galaxy_api_mocked, requests_mock, tmpdir, file_upload_form):
# POST http://bogus.invalid:9443/api/v2/collections/
# requests_mock.get('http://bogus.invalid:9443/api/',
# exc=requests.
exc = exceptions.GalaxyClientAPIConnectionError(requests.exceptions.SSLError('SSL stuff broke'))
requests_mock.post('http://bogus.invalid:9443/api/v2/collections/',
exc=exc)
publish_api_key = '1f107befb89e0863829264d5241111a'
with pytest.raises(exceptions.GalaxyClientAPIConnectionError) as exc_info:
galaxy_api_mocked.publish_file(form=file_upload_form, publish_api_key=publish_api_key)
log.debug('exc_info:%s', exc_info)
3
View Complete Implementation : test_rest_api.py
Copyright GNU General Public License v3.0
Author : ansible
Copyright GNU General Public License v3.0
Author : ansible
def test_galaxy_api_get_collection_detail_SSLError(mocker, galaxy_api, requests_mock):
ssl_msg = 'ssl stuff broke... good luck and godspeed.'
requests_mock.get('http://bogus.invalid:9443/api/v2/collections/some-test-namespace/some-test-name',
exc=requests.exceptions.SSLError(ssl_msg)
)
# ansible_galaxy.exceptions.GalaxyClientAPIConnectionError: ssl stuff broke... good luck and godspeed.
with pytest.raises(exceptions.GalaxyClientAPIConnectionError, match='.*%s.*' % ssl_msg) as exc_info:
galaxy_api.get_collection_detail('some-test-namespace', 'some-test-name')
log.debug('exc_info: %s', exc_info)
3
View Complete Implementation : apiserver.py
Copyright Apache License 2.0
Author : aquasecurity
Copyright Apache License 2.0
Author : aquasecurity
def has_api_behaviour(self, protocol):
try:
r = self.session.get("{}://{}:{}".format(protocol, self.event.host, self.event.port))
if ('k8s' in r.text) or ('"code"' in r.text and r.status_code != 200):
return True
except requests.exceptions.SSLError:
logging.debug("{} protocol not accepted on {}:{}".format(protocol, self.event.host, self.event.port))
except Exception as e:
logging.debug("{} on {}:{}".format(e, self.event.host, self.event.port))
3
View Complete Implementation : test_netscaler_servicegroup.py
Copyright GNU General Public License v3.0
Author : citrix
Copyright GNU General Public License v3.0
Author : citrix
def test_graceful_login_error(self):
self.set_module_state('present')
from ansible.modules.network.netscaler import netscaler_servicegroup
if sys.version_info[:2] == (2, 6):
self.skipTest('requests library not available under python2.6')
client_mock = Mock()
attrs = {'login.side_effect': requests.exceptions.SSLError}
client_mock.configure_mock(**attrs)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_servicegroup',
get_nitro_client=m,
nitro_exception=self.MockException,
):
self.module = netscaler_servicegroup
result = self.failed()
self.astertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully')
3
View Complete Implementation : test_sessions.py
Copyright Apache License 2.0
Author : dana-at-cp
Copyright Apache License 2.0
Author : dana-at-cp
@pytest.mark.parametrize("resource,caught,raised", [
("foo", SSLError(), cpauto.SSLError),
("foo", ConnectionError(), cpauto.ConnectionError),
("foo", HTTPError(), cpauto.HTTPError),
("foo", Timeout(), cpauto.Timeout),
("foo", TooManyRedirects(), cpauto.TooManyRedirects),
("foo", InvalidURL(), cpauto.InvalidURL),
])
def test_http_post_exceptions(core_client, mgmt_server_base_uri, resource, caught, raised):
endpoint = mgmt_server_base_uri + resource
with responses.RequestsMock(astert_all_requests_are_fired=False) as rsps:
rsps.add(responses.POST, endpoint,
body=caught, status=200,
content_type='application/json')
with pytest.raises(raised):
r = core_client.http_post(endpoint=resource, payload={})
3
View Complete Implementation : test_ssl.py
Copyright Apache License 2.0
Author : intel
Copyright Apache License 2.0
Author : intel
def test_wrong_certificate():
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ssl_context.load_cert_chain('tests/ssl/goodkey.crt', 'tests/ssl/goodkey.key')
server = Process(target=run_simple_https_server, args=(ssl_context,))
server.start()
time.sleep(0.5)
with pytest.raises(requests.exceptions.SSLError):
s = requests.Session()
try:
s.mount('https://localhost:8080/', HTTPSAdapter())
s.get('https://localhost:8080/', verify='tests/ssl/wrongRootCA.crt')
server.terminate()
except Exception:
server.terminate()
raise
3
View Complete Implementation : test_ssl.py
Copyright Apache License 2.0
Author : intel
Copyright Apache License 2.0
Author : intel
def test_unsupported_rsa_1024():
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ssl_context.load_cert_chain('tests/ssl/rsa1024.crt', 'tests/ssl/rsa1024.key')
server = Process(target=run_simple_https_server, args=(ssl_context,))
server.start()
time.sleep(0.5)
with pytest.raises(requests.exceptions.SSLError):
s = requests.Session()
try:
s.mount('https://localhost:8080/', HTTPSAdapter())
s.get('https://localhost:8080/', verify='tests/ssl/rootCA.crt')
server.terminate()
except Exception:
server.terminate()
raise