私は Pinax を使用しており、モジュールaccount
を使用してプロジェクトでログイン テストを実行しようとしていrequests
ます。
これは私がしました
def test001_login(self):
#cookies = {'csrftoken': 'a8356fd05b25fad7004994fd5da89596'}
r = requests.post(self.loginurl, data={'username':self.username, 'password': self.password}, auth=(self.username, self.password),allow_redirects=True)
print r.status_code
print r.text
print r.cookies
返された Cookie は空です!! メソッドでget
、クッキーを取得します。この問題の原因は何ですか?
r.text
結果:
<p>Reason given for failure:</p>
<pre>
No CSRF or session cookie.
</pre>
<p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when
<a
href='http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf'>Django's
CSRF mechanism</a> has not been used correctly. For POST forms, you need to
ensure:</p>
私は固執しようとしましcookies
たが、それでも 403 エラーが発生しました。