Python http.server command gives Syntax Error [closed]

2024/11/17 11:45:05

I am trying to start http.server from the Python shell (Python 3.6.2). In the shell, I issue the following commands:

import http.server
import socketserver
python -m http.server 8000 --bind 127.0.0.1

The last line comes directly from the latest Python docs on http.server, but the shell says "Syntax Error."

Then I tried :

python3 -m http.server 8000 --bind 127.0.0.1

But the shell still says "Syntax Error."

Then I tried the simplest command:

python -m http.server also says "Syntax Error":  

But the shell still says "Syntax Error."

What am I doing wrong?

Thanks for any help.

Answer

Because you're having trouble understanding what we mean in the comments; you need to run the command

python -m http.server 8000 --bind 127.0.0.1

from a bash (or similar) shell, NOT from the python IDLE interpreter. They do not mean the same thing. You would have to type the command python into your shell in order to get to you Python IDLE interpreter.

If you're in your python interpreter and would like to exit, press Ctrl+D to return to your bash (or similar) shell. Then, execute the command

python -m http.server 8000 --bind 127.0.0.1

and it should work.

You are right that the python documentation for httpserver could be made more clear but you should know that when you see a call to python it's almost certainly being made from a shell.

https://en.xdnf.cn/q/120206.html

Related Q&A

If statement to check if the value of a variable is in a JSON file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Assign variables to a pandas dataframe when specific cell is empty

I am assigning some variables to values from a data frame. The data frame created using this code data = [[tom, 10], ["", 15], [juli, 14]] df = pd.DataFrame(data, columns=[Name, Age])So after…

Try Except for one variable in multiple variables

I am reading every row in a dataframe and assigning its values in each column to the variables The dataframe created using this code data = [[tom, 10], [, 15], [juli, 14]] df = pd.DataFrame(data, colum…

Print method invalid syntax reversing a string [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

How QRegularExpression can be passed to Qt::MatchRegularExpression

I am trying this sample code that I found which is really really good. I am also trying to figure out the same thing to find an item and scroll to it, but this time I wanted to match the the string whi…

Python list rearrange the elements in a required order

My main list has 44 names as elements. I want to rearrange them in a specific order. I am giving here an example. Note that elements in my actual list are some technical names. No way related to what I…

GMB API accounts.locations.reviews.list

Can i get source code to get reviews using gmb python code also heard mybusiness is discontinued. I tried using my business api is discontinued can i get the implementation process to look for extract…

How to get words from an online text archive such as pastebin?

Im trying to get the words(users) from a text file hosted online, such as from www.site.com/mytextfile.txt or pastebin.com/raw/1111111. I will have multiple "users", one in each line. My code…

Python Histogram using matplotlib on top words

I am reading a file and calculating the frequency of the top 100 words. I am able to find that and create the following list:[(test, 510), (Hey, 362), ("please", 753), (take, 446), (herbert, …

how can I add field in serializer?

Below is my serializer.py file: from rest_framework import serializersclass TaskListSerializer(serializers.Serializer):id = serializers.CharField()user_id = serializers.CharField()status = serializers.…