所以我使用flask来接收表单数据,这对于url编码的数据(application/x-www-form-urlencoded
)工作得很好。我只能访问路由功能中的request.form
。
但是,如果我尝试使用multipart/form-data
发送数据,我会始终收到错误:TypeError: cannot concatenate 'str' and 'NoneType' objects
我尝试访问请求表单时会发生此错误,例如这条线:
f = request.form
。因此我无法实际使用表单数据。无论我是从Fiddler,Postman还是我自己的自定义Java应用程序发送数据,它都会发生。
我是否遗漏了一些用于处理多部分表单数据的代码,或者该请求是否无效?这是邮递员导致错误的示例请求:
这里有完整的追溯(Locus是我的应用,所以只有第18/19行来自我自己的代码):
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python27\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python27\lib\site-packages\flask_debugtoolbar\__init__.py", line 125, in dispatch_request
return view_func(**req.view_args)
File "D:\Programming\VS\Visual Studio 2013\Projects\Locus Backend\Locus Backend\locus\Routing.py", line 67, in url_api_create
f = request.form
File "C:\Python27\lib\site-packages\werkzeug\local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
File "C:\Python27\lib\site-packages\werkzeug\utils.py", line 71, in __get__
value = self.func(obj)
File "C:\Python27\lib\site-packages\werkzeug\wrappers.py", line 483, in form
self._load_form_data()
File "C:\Python27\lib\site-packages\flask\wrappers.py", line 165, in _load_form_data
RequestBase._load_form_data(self)
File "C:\Python27\lib\site-packages\werkzeug\wrappers.py", line 355, in _load_form_data
mimetype, content_length, options)
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 193, in parse
content_length, options)
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 99, in wrapper
return f(self, stream, *args, **kwargs)
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 208, in _parse_multipart
form, files = parser.parse(stream, boundary, content_length)
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 518, in parse
return self.cls(form), self.cls(files)
File "C:\Python27\lib\site-packages\werkzeug\datastructures.py", line 371, in __init__
for key, value in mapping or ():
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 516, in <genexpr>
form = (p[1] for p in formstream if p[0] == 'form')
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 475, in parse_parts
for ellt, ell in self.parse_lines(file, boundary, content_length):
File "C:\Python27\lib\site-packages\werkzeug\formparser.py", line 382, in parse_lines
next_part = b'--' + boundary
TypeError: cannot concatenate 'str' and 'NoneType' objects