Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

fix #2552 by improving request schema check on its initialization

Victor Torresf701f5b0db10
diff --git a/scrapy/http/request/__init__.py b/scrapy/http/request/__init__.py
index d09eaf849..76a428199 100644
--- a/scrapy/http/request/__init__.py
+++ b/scrapy/http/request/__init__.py
@@ -66,7 +66,7 @@ class Request(object_ref):
s = safe_url_string(url, self.encoding)
self._url = escape_ajax(s)
- if ':' not in self._url:
+ if ('://' not in self._url) and (not self._url.startswith('data:')):
raise ValueError('Missing scheme in request url: %s' % self._url)
url = property(_get_url, obsolete_setter(_set_url, 'url'))
diff --git a/tests/test_http_request.py b/tests/test_http_request.py
index 16d7a1cb8..64f1184c3 100644
--- a/tests/test_http_request.py
+++ b/tests/test_http_request.py
@@ -52,6 +52,8 @@ class RequestTest(unittest.TestCase):
def test_url_no_scheme(self):
self.assertRaises(ValueError, self.request_class, 'foo')
+ self.assertRaises(ValueError, self.request_class, '/foo/')
+ self.assertRaises(ValueError, self.request_class, '/foo:bar')
def test_headers(self):
# Different ways of setting headers attribute