Friday 15 March 2013

Searching python cgi environ variable for HTTP_REFERER -



Searching python cgi environ variable for HTTP_REFERER -

i'm trying access http_referer variable within python cgi script using next code:

from cgi import escape import sys, os flip.server.fcgi import wsgiserver def app(environ, start_response): start_response('200 ok', [('content-type', 'text/plain')]) if 'http_referer' in environ: yield 'referer set' else yield 'no referer' wsgiserver(app).run()

problem it, returns 500 error. can't see whats wrong dictionary check. environ contains headers dump of returns:

content_length content_type document_root document_uri fcgi_role gateway_interface https http_accept http_accept_encoding http_accept_language http_cache_control http_connection http_host http_user_agent lang path path_info pwd query_string redirect_status remote_addr remote_port request_method request_uri script_filename script_name server_addr server_name server_port server_protocol server_software term wsgi.errors wsgi.input wsgi.multiprocess wsgi.multithread wsgi.run_once wsgi.url_scheme wsgi.version

any thoughts?

turns out python doesn't utilize if/else structure. worked when wrote this:

if 'http_referer' in environ: yield 'referer set' elif 'http_referer' not in environ: yield 'no referer'

this embarrassing.

python cgi fastcgi

No comments:

Post a Comment