Simple Python HTTP Server

Moderator: Forum moderators

Post Reply
User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Simple Python HTTP Server

Post by rcrsn51 »

Simple Python HTTP Server is here.

User avatar
mikewalsh
Moderator
Posts: 6158
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Simple Python HTTP Server

Post by mikewalsh »

@rcrsn51 :-

I meant to thank you for this wee gem a while back, Bill. Works very well indeed.....and so simple even an idiot like me can use it without any issues. I often wonder where this community would be without your many useful contributions over the years!

Cheers. :thumbup:

Mike. ;)

User avatar
soniabu
Posts: 278
Joined: Fri Jul 24, 2020 6:14 pm
Location: Paris<-->Montreal
Has thanked: 123 times
Been thanked: 32 times

Re: Simple Python HTTP Server

Post by soniabu »

rcrsn51 wrote: Fri May 13, 2022 12:21 pm

Simple Python HTTP Server is here.

Hello rcrsn51,
since it was also in Bookworm synaptic I tried it by exchanging data with my little sister's PC on the LAN
and it works very well as a web server but, unfortunately, I have to turn off my firewall otherwise it won't allow the client to connect
despite having entered the same the new condition: 8000,TCP,UDP,192.168.1.63.
I also had the firewall set up like in the picture but it didn't have any effect.
if https could be used, it would be possible for remote clients to access the web server from the internet
however your info introduced me to a useful sw.
thanks sonia
Image

User avatar
fredx181
Posts: 3070
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1309 times
Contact:

Re: Simple Python HTTP Server

Post by fredx181 »

soniabu wrote: Sun Feb 19, 2023 7:26 pm
rcrsn51 wrote: Fri May 13, 2022 12:21 pm

Simple Python HTTP Server is here.

Hello rcrsn51,
since it was also in Bookworm synaptic I tried it by exchanging data with my little sister's PC on the LAN
and it works very well as a web server but, unfortunately, I have to turn off my firewall otherwise it won't allow the client to connect
despite having entered the same the new condition: 8000,TCP,UDP,192.168.1.63.
I also had the firewall set up like in the picture but it didn't have any effect.
if https could be used, it would be possible for remote clients to access the web server from the internet
however your info introduced me to a useful sw.
thanks sonia

Perhaps if you change the port to 80 (on the server side), it will work.
edit: or open port 8000 in the firewall.

User avatar
wiak
Posts: 4082
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1208 times
Contact:

Re: Simple Python HTTP Server

Post by wiak »

In case useful to anyone else:

The original version of this http server by bones7456, as used by rcrsn51 with his simple gtkdialog frontend, is only written to work with Python version 2.x (2.7 version used in rcrcn51's 1.3 pet).

However, if like me, you only have Python 3.x on your system, you should be able to use the updated version by jjayyyyyyy (FrozenMap) per the below details (though was for python 3.4 so may need some code alterations for more recent python3).

EDIT: You don't need SimpleHTTPServer at all any more for python3 (for downloads). Turns out the functionality has been merged into module http.server, so all you need to do is run command:

Code: Select all

python3 -m http.server 8000

Then on other machine on the LAN point webrowser to <IP address of server>:8000

Actually, 8000 is the default port anyway. Download only this one I think.
Or simply install tiny static webserver 'webfs' and run command: webfsd -p 8000
or put GUI frontend on that...
=============================================

Credit/References:

Python 2.x version

bones7456 relevant published pages (in Chinese, but Chromium offers English page translation):

Code: https://github.com/bones7456/bones7456/ ... hUpload.py

Blog: https://luy.li/2010/05/15/simplehttpserverwithupload/

A simple http server that supports uploading
Now, many people know that there is a SimpleHTTPServer in python, which can be used to easily share files. For example, if you want to send a file to a classmate in the LAN, you just need to cd to the path, and then execute this line:

python -m SimpleHTTPServer

================================================================================================

Python 3.x improved version

Code: https://github.com/jJayyyyyyy/cs/blob/m ... hUpload.py

Blog: https://jjayyyyyyy.github.io/2016/10/07 ... thon3.html

Summary
The version made and improved by bones7456 and BUPTGuo . Since python 2.7 and 3.4 have many different features, I rewrote many functions based on the ideas of the above two students and made a version based on . The main changes are as follows:SimpleHTTPServerWithUploadpy2py3

Rewritten to py3a version based on

Removed StringIO, not used copyfile()

NOTE: If you need a more complex, bigger, but still simple webserver that includes optional "CGI, SSL and Lua support": https://github.com/civetweb/civetweb

It is available as single executable, no installation is required

sthttpd is an alternative http-based really tiny compiled webserver to use if security is a concern, because it has a 'chroot' mode that limits file system access directory. Has a special throttle traffic feature. I use it just now:
https://archlinux.org/packages/communit ... 4/sthttpd/
https://linux.die.net/man/8/thttpd

but for simple LAN use, bones7456 et al SimpleHTTPServer certainly gets the job done so I am installing that too.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
fredx181
Posts: 3070
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1309 times
Contact:

Re: Simple Python HTTP Server

Post by fredx181 »

wiak wrote:

Python 3.x improved version

https://github.com/jJayyyyyyy/cs/blob/m ... hUpload.py

Disadvantage of that HTTPServerWithUpload for python3 is that it doesn't allow to set port number (defaults to 8000)

This one (for python3) does allow to set port nr. : https://gist.github.com/PerfectDay20/df ... 5c0ce68827
Download:
wget --no-check-certificate https://gist.github.com/PerfectDay20/df6ae34372a78867c692025c0ce68827/raw/99e83d96bd975f01a16e3ed8c06f105c465868cb/SimpleHTTPServerWithUpload.py
Make executable:
chmod +x SimpleHTTPServerWithUpload.py
Then run it as ./SimpleHTTPServerWithUpload.py <portnumber>, e.g:
./SimpleHTTPServerWithUpload.py 80

User avatar
wiak
Posts: 4082
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1208 times
Contact:

Re: Simple Python HTTP Server

Post by wiak »

fredx181 wrote: Tue Feb 21, 2023 11:38 am
wiak wrote:

Python 3.x improved version

https://github.com/bones7456/bones7456/ ... hUpload.py

Disadvantage of that HTTPServerWithUpload for python3 is that it doesn't allow to set port number (defaults to 8000)

This one (for python3) does allow to set port nr. : https://gist.github.com/PerfectDay20/df ... 5c0ce68827

Also frozenmap's one didn't work because of language changes between ver 3.4 and 3.8.
For download only http.server works fine and since 'official' hopefully more stable.

Upload handy right enough.

That's the problem with Python, like Lua, you can't rely on it since keeps changing between even version point releases. Perl is difficult but pretty stable. Haven't Googled for perl alternative.

For now I'm likely to use sthttpd - I like its safety features including inbuilt chroot option and permission requirements that avoid major security holes. Busybox httpd fine for simple local webpage serving but for file download use needs extra coded cgi script, which complicates things too much. Alternatively webfsd is good, but again for downloading only I think. No easy answer.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
rockedge
Site Admin
Posts: 6543
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2749 times
Been thanked: 2624 times
Contact:

Re: Simple Python HTTP Server

Post by rockedge »

Why not just use the Hiawatha web server that's built in most Puppy's? Hiawatha can be used as a very simple or very complex web server and remains one of the most secure web server programs in existence.

Really easy to use. Configuration is easy to do on most levels but there is one which might be a factor.

How To -> https://www.hiawatha-webserver.org/howto

Hiawatha manual -> https://www.hiawatha-webserver.org/manpages/hiawatha

User avatar
wiak
Posts: 4082
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1208 times
Contact:

Re: Simple Python HTTP Server

Post by wiak »

rockedge wrote: Tue Feb 21, 2023 1:19 pm

Why not just use the Hiawatha web server

Its absolutely the out of the box no config nature of the python code that makes it so attractive. Not saying its particularly difficult to arrange via Hiawatha.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
rockedge
Site Admin
Posts: 6543
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2749 times
Been thanked: 2624 times
Contact:

Re: Simple Python HTTP Server

Post by rockedge »

@wiak that is true, the python server is simpler and really a good solution. Hiawatha as it is configured already for use of PPLOG and /root/Web-Server with a dedicated user webuser:webgroup so it is already more work than just starting the python web server.

Post Reply

Return to “Filesystem”