Throw InvalidURL not UnicodeError on bad label.
authorCory Benfield <lukasaoz@gmail.com>
Fri, 10 Aug 2012 16:29:12 +0000 (17:29 +0100)
committerCory Benfield <lukasaoz@gmail.com>
Mon, 13 Aug 2012 20:18:56 +0000 (21:18 +0100)
requests/models.py

index 136427f..ae3c1be 100644 (file)
@@ -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 = '/'