Forums

CSRF verification failed after adding cPickle.load()

Hi! I faced with a little bit strange problem for me: after adding the following line

classifier = cPickle.load(open(os.path.join(APP_STATIC,'knn_dc.pck')))

to my code, when I submit a form in gui (and this code executes), I receive the following error into browser:

Forbidden (403)
CSRF verification failed. Request aborted.

Previously I have added these lines to suuport this cPickle.load() function (lib imports successfully, I get csrf error only when I am trying to load my model for machine learning):

import cPickle

APP_ROOT = os.path.dirname(os.path.abspath(__file__))
APP_STATIC = os.path.join(APP_ROOT, 'static')

I disabled csrf in config file, but the error is still here and I have no problems when reading data from txt files with file.open() function.

Could anyone please help to deal with this?

The pickle.load probably has nothing to do with your CSRF issue. When you get a CSRF error, the code in your view has not been executed (CSRF protection is there to protect your view code from being executed when an attacker tries to forge a request).

Search the forums for CSRF and you'll see the ways that people have diagnosed and fixed this problem.