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

From the http.server docs: CGIHTTPRequestHandler can be enabled in the command line by passing the –cgi option: $ python3 -m http.server –bind localhost –cgi 8000 Put your script into cgi_directories: This defaults to [‘/cgi-bin’, ‘/htbin’] and describes directories to treat as containing CGI scripts. Open in the browser: $ python -mwebbrowser http://localhost:8000/cgi-bin/hello.py where hello.py: #!/usr/bin/env … Read more

How to run CGI scripts on Nginx

Nginx doesn’t have native CGI support (it supports fastCGI instead). The typical solution for this is to run your Perl script as a fastCGI process and edit the nginx config file to re-direct requests to the fastCGI process. This is quite a complex solution if all you want to do is run a CGI script. … Read more

How do I remove a query string from URL using Python

import sys if sys.version_info.major == 3: from urllib.parse import urlencode, urlparse, urlunparse, parse_qs else: from urllib import urlencode from urlparse import urlparse, urlunparse, parse_qs url=”http://example.com/?a=text&q2=text2&q3=text3&q2=text4&b#q2=keep_fragment” u = urlparse(url) query = parse_qs(u.query, keep_blank_values=True) query.pop(‘q2’, None) u = u._replace(query=urlencode(query, True)) print(urlunparse(u)) Output: http://example.com/?a=text&q3=text3&b=#q2=keep_fragment

Special Characters in Content-Disposition filename

Firefox, MSIE (starting with version 9), Opera, Konq and Chrome support; MSIE8 and Safari not support; others support is unknown – the encoding defined in RFC 5987. Note that in Content-Disposition: attachment; filename*=UTF-8”weird%20%23%20%80%20%3D%20%7B%20%7D%20%3B%20filename.txt you got the encoding for the Euro character wrong; it’s unicode code point is not %80, fixing this should make it work … Read more

What is HTTPD exactly?

Apache HTTPD is an HTTP server daemon produced by the Apache Foundation. It is a piece of software that listens for network requests (which are expressed using the Hypertext Transfer Protocol) and responds to them. It is open source and many entities use it to host their websites. Other HTTP servers are available (including Apache … Read more

What is difference between PHP cli and PHP cgi?

From http://www.php-cli.com/php-cli-cgi.shtml These are the most important differences between CLI and CGI: Unlike the CGI SAPI, CLI writes no headers to the output by default There are some php.ini directives which are overridden by the CLI SAPI because they do not make sense in shell environments: html_errors: CLI default is FALSE implicit_flush: CLI default is … Read more

How to get rid of non-ascii characters in ruby

Use String#encode The official way to convert between string encodings as of Ruby 1.9 is to use String#encode. To simply remove non-ASCII characters, you could do this: some_ascii = “abc” some_unicode = “áëëçüñżλφθΩ𠜎😸” more_ascii = “123ABC” invalid_byte = “\255” non_ascii_string = [some_ascii, some_unicode, more_ascii, invalid_byte].join # See String#encode documentation encoding_options = { :invalid => :replace, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)