From 79d53d3b8acf021203853e12e8fe0eeb0b742b51 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Fri, 10 Aug 2012 17:29:12 +0100 Subject: [PATCH] Throw InvalidURL not UnicodeError on bad label. --- requests/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 136427f..ae3c1be 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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 = '/' -- 2.34.1