Path: csiph.com!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'configure': 0.04; 'python3': 0.05; 'skip:p 60': 0.05; 'skip:/ 10': 0.07; 'subject:help': 0.07; 'editor.': 0.09; 'mkdir': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:localhost': 0.09; 'python': 0.10; 'apache': 0.14; 'subject:python': 0.14; 'server,': 0.15; '"get': 0.16; "(i'm": 0.16; 'chmod': 0.16; "chris'": 0.16; 'echo': 0.16; 'http.server': 0.16; 'out?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:run': 0.16; 'url:8000': 0.16; 'url:py': 0.16; 'wrote:': 0.16; 'code,': 0.23; 'script': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; "skip:' 10": 0.28; 'cgi': 0.29; 'minimal': 0.30; 'anyone': 0.32; '[1]': 0.32; 'run': 0.33; 'http': 0.33; 'server': 0.34; 'advice': 0.35; 'could': 0.35; 'but': 0.36; 'instead': 0.36; 'url:non-standard http port': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'listing': 0.38; 'files': 0.38; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'hello,': 0.40; 'email addr:gmail.com': 0.62; 'show': 0.62; 'world': 0.64; 'serving': 0.67; 'url:index': 0.67; 'guides': 0.72; 'click': 0.76; '127.0.0.1': 0.84; 'curl': 0.84; 'browser).': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Can anyone help me run python scripts with http.server? Date: Sun, 06 Sep 2015 14:32:06 +0200 Organization: None References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd88de.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441542739 news.xs4all.nl 23858 [2001:888:2000:d::a6]:40997 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96059 tropical.dude.net@gmail.com wrote: > I want to use python for web development but I > could not configure my Apache server to run python > with the guides I found on the internet. > > Can anyone help me configure http.server > to run python scripts? > > I ran the command python -m http.server --cgi to start the http server, > and if I put index.html, I will see the page but if I use > index.py, it doesn't show the page, I can only see the > directory listing of the files and when I click on > index.py, it doesn't run the code, I can see it just > like in the editor. > > Can anyone help me out? While in the long run you're better off if you follow Chris' advice here's a minimal cgi script run with http.server (I'm using curl instead of a browser). $ mkdir cgi-bin $ echo -e '#!/usr/bin/env python3\nprint("Content-type:text/plain")\nprint()\nprint("Hello, world")' > cgi-bin/index.py $ chmod u+x cgi-bin/index.py $ python3 -m http.server --cgi & [1] 12345 $ Serving HTTP on 0.0.0.0 port 8000 ... $ curl http://localhost:8000/cgi-bin/index.py 127.0.0.1 - - [06/Sep/2015 14:30:23] "GET /cgi-bin/index.py HTTP/1.1" 200 - Hello, world $