scrapy/scrapy — pull request #811 by nramirezuy (2014-07-21 22:38:20+00:00)
Title: FormRequest formdata drop None values #667

Implementation of: #412 #667

Current:

```python
>>> from scrapy.http import FormRequest, HtmlResponse>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))
>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))

>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))

>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))

>>> FormRequest("http://website.com?a=1&b=1", method = "GET", formdata = {"a":None, "c":"3"})
Traceback (most recent call last):
File "", line 1, in
File "scrapy/http/request/form.py", line 27, in __init__
querystr = _urlencode(items, self.encoding)
File "scrapy/http/request/form.py", line 52, in _urlencode
for v in (vs if hasattr(vs, '__iter__') else [vs])]
File "scrapy/utils/python.py", line 82, in unicode_to_str
raise TypeError('unicode_to_str must receive a unicode or str object, got %s' % type(text).__name__)
TypeError: unicode_to_str must receive a unicode or str object, got NoneType
```
With patch:
```python
>>> from scrapy.http import FormRequest, HtmlResponse>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))
>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))

>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))

>>> FormRequest.from_response(HtmlResponse(url='http://website.com', body='

'))

>>> FormRequest("http://website.com?a=1&b=1", method = "GET", formdata = {"a":None, "c":"3"})

>>> FormRequest("http://website.com", method = "GET", formdata = {"a":None, "c":"3"})

```