Solved

Start a local https server with Python

Posted on 2014-11-26
4
496 Views
Last Modified: 2014-11-26
i am trying to Start a local https server with Python by doing the following but getting
>>> python -m HTTPServer 8001
SyntaxError: invalid syntax

I cant see any online docs that explain how to do this type of simple direct command?
0
Comment
Question by:pcomb
  • 3
4 Comments
 

Author Comment

by:pcomb
ID: 40467243
i also tried
import http.server
python -m http.server 8000
but still getting invalid syntax
0
 

Author Comment

by:pcomb
ID: 40467254
using 3.4.2
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 40467439
python -m http.server is run from the command line.  
C:\Users\mark>python -m http.server
Serving HTTP on 0.0.0.0 port 8000 ...

Open in new window


If you're trying to start it from within the interpreter or a script-- which based on your invalid syntax error it looks like that's what you're doing, you'd use this:
import http.server
http.server.test(HandlerClass=http.server.SimpleHTTPRequestHandler, port=8000)

Open in new window


But this isn't an HTTPS server.  It's just HTTP.  If you want HTTPS, you'd have to do something like this http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/.  That link is for Python 2 but the idea is the same for 3.  You'd need to change the underlying socket to a SSL capable one.
0
 

Author Comment

by:pcomb
ID: 40467875
great thank you
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question