Here are the examples of the python api requests.exceptions.MissingSchema taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
3
Example 1
Project: pipreqs Source File: test_pipreqs.py
def test_custom_pypi_server(self):
"""
Test that trying to get a custom pypi sever fails correctly
"""
self.assertRaises(requests.exceptions.MissingSchema, pipreqs.init, {'<path>': self.project, '--savepath': None,
'--use-local': None, '--force': True, '--proxy': None, '--pypi-server': 'nonexistent'})
3
Example 2
def test_req(self):
self.g.rule_payload = {'query': 'bieber', 'maxResults': 10, 'publisher': 'twitter'}
self.g.stream_url = self.g.end_point
self.assertEquals(10, len(json.loads(self.g.request())["results"]))
self.g.stream_url = "adsfadsf"
with self.assertRaises(requests.exceptions.MissingSchema) as cm:
self.g.request()
self.g.stream_url = "http://ww.thisreallydoesn'texist.com"
with self.assertRaises(requests.exceptions.ConnectionError) as cm:
self.g.request()
self.g.stream_url = "https://ww.thisreallydoesntexist.com"
with self.assertRaises(requests.exceptions.ConnectionError) as cm:
self.g.request()
3
Example 3
Project: nap Source File: test_nap.py
def test_requests_raises_error(self):
"""Test that requests properly raises its own errors
>>> requests.get('/kk')
requests.exceptions.MissingSchema: Invalid URL u'/kk':
No schema supplied. Perhaps you meant http:///kk?
"""
url = Url('')
self.assertRaises(requests.exceptions.MissingSchema, url.get)
0
Example 4
Project: PrimCom Source File: urlshortener.py
def shorten_url(long_url):
long_url = simplify_url(long_url)
classes = [shorteners.GoogleShortener,
shorteners.TinyurlShortener,
shorteners.IsgdShortener]
for cl in classes:
try:
if not is_valid_url(long_url):
raise InvalidUrlException
obj = cl()
short_url = obj.short(long_url)
expanded = obj.expand(short_url)
show_short_url(short_url, long_url, expanded)
break
except InvalidUrlException:
print("Error: invalid URL.")
break
except ShorteningErrorException as e:
print('# {cl}: {err}.'.format(cl=obj.__class__.__name__, err=e))
except requests.exceptions.MissingSchema as e:
print('# error:', e)
break
0
Example 5
def safe(func):
"""
Make sure that a test does not access external resources.
Note: This will mock `requests.get`. If you are mocking it yourself
already, this will throw an assertion error.
"""
@patch("appvalidator.testcases.webappbase.test_icon")
@wraps(func)
def wrap(test_icon, *args, **kwargs):
# Assert that we're not double-mocking `requests.get`.
from requests import get as _r_g
assert not isinstance(_r_g, (MagicMock, Mock)), (
"`requests.get` already mocked")
with patch("requests.get") as r_g:
def request_generator(*args, **kwargs):
url = kwargs.get("url", args[0])
if "://" not in url:
raise requests.exceptions.MissingSchema
request = Mock()
request.text = "foo bar"
request.status_code = 200
request.encoding = 'UTF-8'
# The first bit is the return value. The second bit tells whatever
# is requesting the data that there's no more data.
request.raw.read.side_effect = [request.text, ""]
return request
r_g.side_effect = request_generator
return func(*args, **kwargs)
return wrap
0
Example 6
Project: filmkodi Source File: webUtils.py
def getSource(self, url, form_data, referer, xml=False, mobile=False):
url = self.fixurl(url)
if not referer:
referer = url
else:
referer = self.fixurl(referer)
headers = {'Referer': referer}
if mobile:
self.s.headers.update({'User-Agent' : 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'})
if xml:
headers['X-Requested-With'] = 'XMLHttpRequest'
if 'dinozap.info' in urlparse.urlsplit(url).netloc:
headers['X-Forwarded-For'] = '178.162.222.111'
if 'playerhd2.pw' in urlparse.urlsplit(url).netloc:
headers['X-Forwarded-For'] = '178.162.222.121'
if 'playerapp1.pw' in urlparse.urlsplit(url).netloc:
headers['X-Forwarded-For'] = '178.162.222.122'
if 'finecast.tv' in urlparse.urlsplit(url).netloc:
self.s.headers.update({'Cookie' : 'PHPSESSID=d08b73a2b7e0945b3b1bb700f01f7d72'})
if form_data:
#ca**on.tv/key.php
if 'uagent' in form_data[0]:
form_data[0] = ('uagent',urllib.quote(self.s.headers['User-Agent']))
if '123456789' in form_data[0]:
import random
cotok = str(random.randrange(100000000, 999999999))
form_data[0] = ('token',cotok)
r = self.s.post(url, headers=headers, data=form_data, timeout=20, cookies = {'token' : cotok})
else:
r = self.s.post(url, headers=headers, data=form_data, timeout=20)
response = r.text
else:
try:
r = self.s.get(url, headers=headers, timeout=20, verify=False)
response = r.text
except (requests.exceptions.MissingSchema):
response = 'pass'
print(">>>>>>>>>>>>> LEN <<<<<<<<<", len(response))
#if len(response) > 10:
if self.cookie_file:
self.save_cookies_lwp(self.s.cookies, self.cookie_file)
return HTMLParser().unescape(response)
0
Example 7
Project: filmkodi Source File: webUtils.py
def getSource(self, url, form_data, referer, xml=False, mobile=False):
url = self.fixurl(url)
if not referer:
referer = url
else:
referer = self.fixurl(referer)
headers = {'Referer': referer}
if mobile:
self.s.headers.update({'User-Agent' : 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'})
if xml:
headers['X-Requested-With'] = 'XMLHttpRequest'
if 'dinozap.info' in urlparse.urlsplit(url).netloc:
headers['X-Forwarded-For'] = '178.162.222.111'
if 'playerhd2.pw' in urlparse.urlsplit(url).netloc:
headers['X-Forwarded-For'] = '178.162.222.121'
if 'playerapp1.pw' in urlparse.urlsplit(url).netloc:
headers['X-Forwarded-For'] = '178.162.222.122'
if 'finecast.tv' in urlparse.urlsplit(url).netloc:
self.s.headers.update({'Cookie' : 'PHPSESSID=d08b73a2b7e0945b3b1bb700f01f7d72'})
if form_data:
#ca**on.tv/key.php
if 'uagent' in form_data[0]:
form_data[0] = ('uagent',urllib.quote(self.s.headers['User-Agent']))
if '123456789' in form_data[0]:
import random
cotok = str(random.randrange(100000000, 999999999))
form_data[0] = ('token',cotok)
r = self.s.post(url, headers=headers, data=form_data, timeout=20, cookies = {'token' : cotok})
else:
r = self.s.post(url, headers=headers, data=form_data, timeout=20)
response = r.text
else:
try:
r = self.s.get(url, headers=headers, timeout=20)
response = r.text
except (requests.exceptions.MissingSchema):
response = 'pass'
print(">>>>>>>>>>>>> LEN <<<<<<<<<", len(response))
#if len(response) > 10:
if self.cookie_file:
self.save_cookies_lwp(self.s.cookies, self.cookie_file)
return HTMLParser().unescape(response)
0
Example 8
Project: ospurge Source File: client.py
def perform_on_project(admin_name, password, project, auth_url,
endpoint_type='publicURL', action='dump',
insecure=False, **kwargs):
"""Perform provided action on all resources of project.
action can be: 'purge' or 'dump'
"""
session = base.Session(admin_name, password, project, auth_url,
endpoint_type, insecure, **kwargs)
error = None
for rc in constants.RESOURCES_CLASSES:
try:
resources = globals()[rc](session)
res_actions = {'purge': resources.purge,
'dump': resources.dump}
res_actions[action]()
except (exceptions.EndpointNotFound,
api_exceptions.EndpointNotFound,
neutronclient.common.exceptions.EndpointNotFound,
cinderclient.exceptions.EndpointNotFound,
novaclient.exceptions.EndpointNotFound,
heatclient.openstack.common.apiclient.exceptions.EndpointNotFound,
exceptions.ResourceNotEnabled):
# If service is not in Keystone's services catalog, ignoring it
pass
except requests.exceptions.MissingSchema as e:
logging.warning(
'Some resources may not have been deleted, "{!s}" is '
'improperly configured and returned: {!r}\n'.format(rc, e))
except (ceilometerclient.exc.InvalidEndpoint, glanceclient.exc.InvalidEndpoint) as e:
logging.warning(
"Unable to connect to {} endpoint : {}".format(rc, e.message))
error = exceptions.InvalidEndpoint(rc)
except (neutronclient.common.exceptions.NeutronClientException):
# If service is not configured, ignoring it
pass
if error:
raise error
0
Example 9
Project: syntribos Source File: test_http_checks.py
def test_missing_schema(self):
signal = http_checks.check_fail(rex.MissingSchema())
self._assert_has_tags(self.bad_request_tags, signal)
self._assert_has_slug("HTTP_FAIL_MISSING_SCHEMA", signal)