我的代碼是:如何在Python(brubeck)中解析表單發佈的數據?
class GameSession(JSONMessageHandler, UserHandlingMixin):
@allow_all
def post(self):
s = self.s = Session()
payload = self.message.body
# payload = json.loads(payload)
print 'payload start'
print payload
print 'payload end'
current_gamesession = self.check_gamesession(payload.prize_id,
payload.publisher_id)
我看到的是:
payload start
prize_id=2&publisher_id=32&foreign_user_id=1234
payload end
ERROR:root:'str' object has no attribute 'prize_id'
Traceback (most recent call last):
File "/home/vagrant/src/brubeck/brubeck/request_handling.py", line 338, in __call__
rendered = fun(*self._url_args)
File "/vagrant/mysite/api/views.py", line 31, in wrapper
return func(self, *args, **kwargs)
File "/vagrant/mysite/api/views.py", line 629, in post
如何獲得表單數據?
**編輯** 順便說一句,這就是如果我發送數據x-www-form-urlencoded
。如果我作爲form-data
送,我得到:
payload start
------WebKitFormBoundaryFX1GuivvAA42T3uk
Content-Disposition: form-data; name="prize_id"
2
------WebKitFormBoundaryFX1GuivvAA42T3uk
Content-Disposition: form-data; name="publisher_id"
1
------WebKitFormBoundaryFX1GuivvAA42T3uk
Content-Disposition: form-data; name="foreign_user_id"
2321
------WebKitFormBoundaryFX1GuivvAA42T3uk--
payload end
什麼框架,您使用的? –
我正在使用'brubeck' – Shamoon
您的意思是:http://brubeck.io/ – jfs