Solved

Start a local https server with Python

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
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 …

705 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