cgi

Python 3.0 urllib.parse error “Type str doesn't support the buffer API”

浪尽此生 提交于 2019-11-27 03:46:31
问题 File "/usr/local/lib/python3.0/cgi.py", line 477, in __init__ self.read_urlencoded() File "/usr/local/lib/python3.0/cgi.py", line 577, in read_urlencoded self.strict_parsing): File "/usr/local/lib/python3.0/urllib/parse.py", line 377, in parse_qsl pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')] TypeError: Type str doesn't support the buffer API Can anybody direct me on how to avoid this? I'm getting it through feeding data into the cgi.Fieldstorage and I can't seem to do it any

How to run CGI “hello world” with python http.server

巧了我就是萌 提交于 2019-11-27 03:13:21
问题 I am using Windows 7 and Python 3.4.3. I would like to run this simple helloworld.py file in my browser: print('Content-Type: text/html') print( '<html>') print( '<head></head>') print( '<body>') print( '<h2>Hello World</h2>') print( '</body></html>') What I do is: 1) Go to command line C:\Python (where python is installed) 2) run: python -m http.server 3) Got to Firefox and type http://localhost:8000/hello.py However, instead of "Hello World", the browser just prints the content of the hello

How to host python cgi script with `python -m SimpleHTTPServer 8000` or `python -m CGIHTTPServer 8000`?

点点圈 提交于 2019-11-27 02:11:16
问题 When I run python -m SimpleHTTPServer 8000 or python -m CGIHTTPServer 8000 in my shell I am hosting the content of my current directory to the internet. I would like to make the following cgi_script.py work correctly using the above command in the command line when I browse to 192.xxx.x.xx:8000/cgi_script.py #!/usr/bin/env python print "Content-Type: text/html" print print """\ <html> <body> <h2>Hello World!</h2> </body> </html> """ But this script is displayed literally and not only the

Dynamically serving a matplotlib image to the web using python

天大地大妈咪最大 提交于 2019-11-27 01:03:04
This question has been asked in a similar way here but the answer was way over my head (I'm super new to python and web development) so I'm hoping there's a simpler way or it could be explained differently. I'm trying to generate an image using matplotlib and serve it without first writing a file to the server. My code is probably kind of silly, but it goes like this: import cgi import matplotlib.pyplot as pyplot import cStringIO #I think I will need this but not sure how to use ...a bunch of matplotlib stuff happens.... pyplot.savefig('test.png') print "Content-type: text/html\n" print """

Executing a Python script in Apache2

冷暖自知 提交于 2019-11-27 00:48:28
问题 I am trying to execute a Python program using Apache. However, Apache will only serve the file and not actually execute it. The permissions on the file are r/w/x and it is in /var/www . I will post the contents of httpd.conf and the program code after. I also tried to running the python script as a .cgi file but that did not work as well. I have both the mod_python and mod_wsgi modules loaded into apache as well. Python sample: #!/usr/bin/python # enable debugging import cgitb cgitb.enable()

Is it faster to access data from files or a database server?

谁都会走 提交于 2019-11-27 00:16:43
问题 If I have a static database consisting of folders and files, would access and manipulation be faster than SQL server type databases, considering this would be used in a CGI script? When working with files and folders, what are the tricks to better performance? 回答1: I'll add to the it depends crowd. This is the kind of question that has no generic answer but is heavily dependent on the situation at hand. I even recently moved some data from a SQL database to a flat file system because the

How can I determine if a script was called from the command line or as a cgi script?

南笙酒味 提交于 2019-11-26 23:22:43
问题 I have a script that I wrote that can either be used on the command line or as a CGI script, and need to determine how the script was called so I can output a content-type header for web requests (and maybe some anti-cache headers too). My first thought is to check for the existance of http environment variables: my $js = build_javascript(); if ( exists $ENV{HTTP_HOST} ) { print "Content-type: text/javascript\n\n"; } print $js; Is there a better way? 回答1: According to the CGI specification in

Multipart upload form: Is order guaranteed?

ぐ巨炮叔叔 提交于 2019-11-26 23:13:24
问题 It appears that when I use an html form to make a "Content-Type: multipart/form-data" POST request, the fields always appear in the order in which they are listed in the HTML. In practice, do all browsers do this? The primary motivation for wanting to know this is so I can do server-side validation of form data w/o being required to cache the entire HTTP request in RAM | disk first. I know CGI, PHP, etc typically won't do anything 'til the upload completes. Probably because RFC 2388 section 5

How to parse $QUERY_STRING from a bash CGI script

为君一笑 提交于 2019-11-26 22:39:28
I have a bash script that is being used in a CGI. The CGI sets the $QUERY_STRING environment variable by reading everything after the ? in the URL. For example, http://example.com?a=123&b=456&c=ok sets QUERY_STRING=a=123&b=456&c=ok . Somewhere I found the following ugliness: b=$(echo "$QUERY_STRING" | sed -n 's/^.*b=\([^&]*\).*$/\1/p' | sed "s/%20/ /g") which will set $b to whatever was found in $QUERY_STRING for b . However, my script has grown to have over ten input parameters. Is there an easier way to automatically convert the parameters in $QUERY_STRING into environment variables usable

How can I fork a background processes from a Perl CGI script on Windows?

試著忘記壹切 提交于 2019-11-26 22:25:06
问题 I've had some trouble forking of processes from a Perl CGI script when running on Windows. The main issue seems to be that 'fork' is emulated when running on windows, and doesn't actually seem to create a new process (just another thread in the current one). This means that web servers (like IIS) which are waiting for the process to finish continue waiting until the 'background' process finishes. Is there a way of forking off a background process from a CGI script under Windows? Even better,