Solved

Start a local https server with Python

Posted on 2014-11-26
4
482 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now