1

I'm trying to launch a simple server from a Python script:

 server = Popen(['python' ,'-m', 'SimpleHTTPServer', '9090'], stderr=STDOUT, stdout=PIPE)
 output = server.communicate()[0] # <- DEBUG

Reading the output, I see:

'/usr/bin/python: Import by filename is not supported.'

What's the problem? How to solve it?

Shawn Chin
87.4k20 gold badges168 silver badges193 bronze badges
asked Jun 1, 2012 at 12:56
7
  • Works fine for me. Make it log to the screen directly. Let's see what it says. Also, don't import Popen and the rest of subprocess into your current namespace. Commented Jun 1, 2012 at 13:00
  • can't log to the screen as it is withing a library and it's not a console application. Commented Jun 1, 2012 at 13:02
  • I tested your code on windows and it works fine. Commented Jun 1, 2012 at 13:18
  • 3
    +1 to Noufal - my guess is that it's environmental - the "python" being invoked by Popen ('/usr/bin/python' based on the output) might be a different version, but one of the PYTHON...PATH environment variables might be pointing somewhere else... Commented Jun 1, 2012 at 13:49
  • 2
    Try sys.executable instead of 'python'. Commented Jun 1, 2012 at 14:03

1 Answer 1

1

I suggest change to code to this:

import SimpleHTTPServer
import SocketServer
PORT = 9090
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
answered Dec 21, 2018 at 7:50
Sign up to request clarification or add additional context in comments.

1 Comment

This has the decided disadvantage that the script cannot perform other tasks while the server runs in the background.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.