Session count is not saved

Works with Python 2.7, Apache + mod_wsgi on CentOS 6.3

Everything works fine when I am on the local host. However, when I run the vm code in Azure, I don’t see the session information being saved on all pages.

Mostly in my views I have something like:

@frontend.route('/') def index(): session['foo'] = 'bar' print session['foo'] return redirect(url_for("frontend.page2")) @frontend.route('page2') def page2(): print session 

Print Output:

 bar <SecureCookieSession {}> 

My wsgi configuration for apache:

 WSGISocketPrefix /var/run/wsgi <VirtualHost *:80> ServerName example.com ServerAlias example.com WSGIDaemonProcess myproj threads=5 processes=5 WSGIScriptAlias / /home/mydir/myproj/apache/myproj.wsgi <Directory /home/mydir/myproj> WSGIScriptReloading On WSGIProcessGroup myproj WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> </VirtualHost> 

I have a set of secret_key:

 app.secret_key = os.urandom(24) 

I tried with setting SERVER_NAME, but this did not help:

 app.config['SERVER_NAME'] = 'example.com' 

Any ideas on how I can debug this anymore?

Thanks!

+6
source share
1 answer

Do not use app.secret_key = os.urandom(24) !

You should enter a static value here, and not read from os.urandom every time. You probably misunderstood the example in docs , it shows you how you can read random data from os.urandom , but it also clearly states:

Just grab this thing and copy / paste it into your code and you are done

If you read it at runtime, then each of your workflows will have a different secret key! This means that if the request is being processed by another worker, the session is terminated because the cookie is signed with the wrong secret key.

+22
source

Source: https://habr.com/ru/post/953527/


All Articles