Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Start a local https server with Python

Posted on 2014-11-26
4
Medium Priority
?
632 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
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 …
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…

670 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