diff --git a/scrapy/http/request/__init__.py b/scrapy/http/request/__init__.py index 9f2161674..7fd034890 100644 --- a/scrapy/http/request/__init__.py +++ b/scrapy/http/request/__init__.py @@ -25,7 +25,7 @@ class Request(object_ref): dont_filter=False, errback=None): self._encoding = encoding # this one has to be set first - self.method = method.upper() + self.method = str(method).upper() self._set_url(url) self._set_body(body) self.priority = priority diff --git a/scrapy/tests/test_http_request.py b/scrapy/tests/test_http_request.py index e9da2d3b3..841568ed8 100644 --- a/scrapy/tests/test_http_request.py +++ b/scrapy/tests/test_http_request.py @@ -162,6 +162,10 @@ class RequestTest(unittest.TestCase): self.assertEqual(r4.meta, {}) assert r4.dont_filter is False + def test_method_always_str(self): + r = self.request_class("http://www.example.com", method=u"POST") + assert isinstance(r.method, str) + def test_weakref_slots(self): """Check that classes are using slots and are weak-referenceable""" x = self.request_class('http://www.example.com')