mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
+4
-1
@@ -413,7 +413,10 @@ class Request(object):
|
||||
if not scheme in SCHEMAS:
|
||||
raise InvalidSchema("Invalid scheme %r" % scheme)
|
||||
|
||||
netloc = netloc.encode('idna').decode('utf-8')
|
||||
try:
|
||||
netloc = netloc.encode('idna').decode('utf-8')
|
||||
except UnicodeError:
|
||||
raise InvalidURL('URL has an invalid label.')
|
||||
|
||||
if not path:
|
||||
path = '/'
|
||||
|
||||
@@ -19,6 +19,7 @@ from requests.compat import str, StringIO
|
||||
from requests import HTTPError
|
||||
from requests import get, post, head, put
|
||||
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
|
||||
from requests.exceptions import InvalidURL
|
||||
|
||||
if 'HTTPBIN_URL' not in os.environ:
|
||||
os.environ['HTTPBIN_URL'] = 'http://httpbin.org/'
|
||||
@@ -1062,6 +1063,10 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
|
||||
"""Test that `bytes` can be used as the values of `files`."""
|
||||
post(httpbin('post'), files={'test': b'test'})
|
||||
|
||||
def test_invalid_urls_throw_requests_exception(self):
|
||||
"""Test that URLs with invalid labels throw
|
||||
Requests.exceptions.InvalidURL instead of UnicodeError."""
|
||||
self.assertRaises(InvalidURL, get, 'http://.google.com/')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user