0

I send a HTTP request from a client. Then on the server I try to validate a WTForm Form.

from webob.multidict import MultiDict

from wtforms import Form, TextField, PasswordField, validators

class LoginForm(Form):
    email = TextField('Email', [validators.Required(), validators.Email()])
    password = PasswordField('Password', [validators.Required()])

The following commands are executed inside a RequestHandler:

self.request.body
>>> '{"username":"my_email@me.com", "password":"pass"}'

json.loads(self.request.body)
>>>  {"username":"my_email@me.com", "password":"pass"}

type(json.loads(self.request.body))

>>> type 'dict'

MultiDict(json.loads(self.request.body))

>>> MultiDict[(u'username', u'my_email@me.com'), (u'password':'******')])

LoginForm(MultiDict(json.loads(self.request.body))).data

>>> {'password': 'pass', 'email': u''}

From the last command I'm expecting to see {"username":"my_email@me.com", "password":"pass"} which I can later validate. However, somehow the actual data is 'lost'. Any ideas?

X-Istence
  • 16,324
  • 6
  • 57
  • 74
LLaP
  • 2,528
  • 4
  • 22
  • 34
  • When you posted the result of the `MultiDict` you show `(u'password':'******')` which is not a valid tuple, are you sure that is what the output was? – X-Istence Dec 29 '15 at 22:39

1 Answers1

0

Your login form has the fields named email and password yet you are passing it the fields username and password.

Change one or the other to match, and you should be good to go.

X-Istence
  • 16,324
  • 6
  • 57
  • 74