Simple Python Web Server

  Рет қаралды 253,688

howCode

howCode

6 жыл бұрын

In this video we'll be creating a really simple web server in Python using the Python http library.
Go to howcode.org for more!
Source code: howco.de/simple-python-web-se...
Link to DigitalOcean: howco.de/d_ocean
Link to howCode Facebook: howco.de/fb
Link to howCode Twitter: howco.de/twitter
Link to /r/howCode: howco.de/reddit
Don't forget to subscribe for more!

Пікірлер: 140
@tsaligm6320
@tsaligm6320 3 жыл бұрын
This is not only a great beginner project, but also a very lightweight server for any needs
@necodaley5386
@necodaley5386 6 жыл бұрын
Thanks for making this video. You explained something that didn't really understand but now I understand it. Thanks again for making this video hope to more videos on servers
@mikethegamedev
@mikethegamedev 3 жыл бұрын
Such high quality content! 👍👍👍
@matiasarenas7706
@matiasarenas7706 2 жыл бұрын
Thanks 4 the code! It's a late thanks, but with good vibes (y)
@user-iw5de9ou6u
@user-iw5de9ou6u 5 жыл бұрын
i like this tutorial, direct to the point
@abdurrazzak1612
@abdurrazzak1612 2 жыл бұрын
Such high quality content!
@eloyperezrodriguez2218
@eloyperezrodriguez2218 4 жыл бұрын
Thanks for the tutorial! It has helped me a lot :D
@prestonwallitsch8636
@prestonwallitsch8636 3 жыл бұрын
thank you so freaking much. I am a beginner at python and I was having trouble finding out how to do this.
@manosped4202
@manosped4202 4 жыл бұрын
sorry if the questing is dumb but how can we publish it on the net or show this to our friends?
@atomruby4096
@atomruby4096 4 жыл бұрын
Straight to the point, nice !
@sanchogodinho8769
@sanchogodinho8769 3 жыл бұрын
Wow! It REALLY works!!!
@dixyfrex4537
@dixyfrex4537 5 жыл бұрын
which editor do you use?
@georgeseletski8241
@georgeseletski8241 3 жыл бұрын
Thanks THE BEST VIDEO I"VE SEEN!!!
@StephenPoole-of4qc
@StephenPoole-of4qc 4 ай бұрын
Why do you put the [1:] when opening and reading the file?
@julianosvonskingrad7009
@julianosvonskingrad7009 2 жыл бұрын
Question: Is the python script executed? Constantly running?
@deni86
@deni86 4 жыл бұрын
Thanks a lot bro, helped out a lot!
@kevinl7139
@kevinl7139 6 жыл бұрын
More simple python stuff please!
@maramismail432
@maramismail432 5 жыл бұрын
what the program use ?
@nagasesanagasesa7026
@nagasesanagasesa7026 3 жыл бұрын
can this replace flask?
@hamzadaoud2653
@hamzadaoud2653 4 жыл бұрын
so this is mean i won't need to install Apache2 or kickweb server ... ?
@Maexwellus
@Maexwellus 5 ай бұрын
can you tell me how to add ccs to that ?
@krin3x93
@krin3x93 3 жыл бұрын
so if i port forward the ip and the port that is assigned, i should be able to access it through the internet?
@why1t
@why1t 3 жыл бұрын
Yes
@Solomonwo
@Solomonwo 2 жыл бұрын
How to do that?
@trieule2012
@trieule2012 3 жыл бұрын
what is DS_Store, ser?
@willum7981
@willum7981 4 жыл бұрын
Great video, keep it up!
@endoman3301
@endoman3301 4 жыл бұрын
What version of python it is?
@alisaleh1900
@alisaleh1900 Жыл бұрын
Thanks a lot
@homieluca
@homieluca 4 жыл бұрын
now how can i unpoad a file to this webserber ?
@Ftoy-OG
@Ftoy-OG 3 жыл бұрын
Never sending content header but closing it, seems legit
@scamcaller
@scamcaller 5 жыл бұрын
looks like i can very easily execute any file in the root directory only if I know their names
@AMGKarim404
@AMGKarim404 6 жыл бұрын
nice bro that was help thnx alot
@hanoufhaz1991
@hanoufhaz1991 3 жыл бұрын
what platform did you use here, I am using only notepad++ , can I still open webserver by it ?
@കൊച്ചുണ്ണി
@കൊച്ചുണ്ണി 5 ай бұрын
I know it's been two years. But if you are asking about from where he opened the webserver, its from his browser. Not the IDE or text editor. When he executes the python program, he is serving the webserver on his localhost at port 8080 and he is accessing the localhost from the browser.
@imagineexistance4538
@imagineexistance4538 5 жыл бұрын
My first web server!
@GerardoWacker
@GerardoWacker 6 жыл бұрын
Thank you for the tutorial! It's very simple to make, but my question is, Is there a way to change the server name? (for example, Apache, nginx, and cloudflare uses a server called cloudflare-nginx)
@user-wz3pi1vh7o
@user-wz3pi1vh7o 4 жыл бұрын
what
@DominicNweze
@DominicNweze Жыл бұрын
I dotn really care about the server name, but issue is that other devices can't even assess the server or site.
@TheSlyProductions
@TheSlyProductions 4 жыл бұрын
How would you serve a CSS file along with the HTML?
@user-rv5qf1ud6j
@user-rv5qf1ud6j 4 жыл бұрын
You can refer to the file from index.html.
@dasdunetechnologies1695
@dasdunetechnologies1695 5 жыл бұрын
nice ! maybe next step is to handle a POST request ?
@MichaelKopanaslike
@MichaelKopanaslike 4 жыл бұрын
what IDE do you have?
@davidrodenkirchen4666
@davidrodenkirchen4666 4 жыл бұрын
Looks like PyCharm
@increadibleangel7980
@increadibleangel7980 6 жыл бұрын
I have website....how can I make it run user input python code...Like cideacademy
@prestonwallitsch8636
@prestonwallitsch8636 3 жыл бұрын
Can you use this to create an html webpage?
@Henry_Nunez
@Henry_Nunez 3 жыл бұрын
yes
@evolvedanimeisland
@evolvedanimeisland 6 жыл бұрын
great video, its nice that you showed how to code your own server although all that was not necessary. go to command line type python -m http.server 8000 and you are done.....good job though
@drcmyway5064
@drcmyway5064 5 жыл бұрын
Which software is used to run the code
@khalifaharuna9852
@khalifaharuna9852 5 жыл бұрын
atom
@samuelhulme8347
@samuelhulme8347 5 жыл бұрын
Or python it self
@MeloIZCor3
@MeloIZCor3 5 жыл бұрын
How do I add this web server page to a website like Wix or Wordpress?
@zerokun2655
@zerokun2655 3 жыл бұрын
if i go to localhost:8080 it says file not found but i did add the if to "redirect" to index.html :(
@hardikp5192
@hardikp5192 3 жыл бұрын
same here bro
@club6525
@club6525 6 жыл бұрын
how do you setup the html file?
@dakathulatris728
@dakathulatris728 5 жыл бұрын
Please, can you share the theme and syntax you are using on atom?
@janikneil1766
@janikneil1766 4 жыл бұрын
It's VS Code
@gabriellindgren3447
@gabriellindgren3447 3 жыл бұрын
@@janikneil1766 nah, that’s definitley Atom
@umarbello6022
@umarbello6022 3 жыл бұрын
Awesome
@urdad1656
@urdad1656 3 жыл бұрын
how do i launch a server
@mandunna
@mandunna 6 жыл бұрын
anyone getting "socket.gaierror: [Errno 8] nodename nor servname provided, or not known" when running?
@justgivemethetruth
@justgivemethetruth 5 жыл бұрын
Wow, that is pure amazing. How hard would it be to add CGI capabilities to this? I want to create a local web server to my machine that will serve portions of the filesystem, like home dir, or media directories and has controls to do manipulations on files if the user has the right permissions. Can this serve things like video, audio, images, etc? I am so glad I found this - all the other similiar things always want people to use these frameworks like FLASK or whatnot and the point for me is to learn and use Python.
@chonkydog6262
@chonkydog6262 4 жыл бұрын
yes
@clusion1405
@clusion1405 3 жыл бұрын
Is it possible to run PHP on that webserver
@neevot
@neevot 3 жыл бұрын
no
@lynx-me2ew
@lynx-me2ew 4 жыл бұрын
can i reach this server from other networks ?????? if not please write me if you make a video about it
@neevot
@neevot 3 жыл бұрын
in theory, yes
@thomastsojan4367
@thomastsojan4367 4 жыл бұрын
Does this support realtime communication
@amineabdz
@amineabdz 4 жыл бұрын
it depends , this is a TCP server so it is a realtime communication Server but you might want to create a UDP server in which case you should consult other tutorials
@JoJo1236
@JoJo1236 5 жыл бұрын
What about a multi threaded web server?
@aleksejskirikovs8903
@aleksejskirikovs8903 4 жыл бұрын
# -*- coding: utf-8 -*- import urllib import settings as sett from datetime import datetime from SocketServer import ThreadingMixIn from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class HOMEServer(ThreadingMixIn, HTTPServer): daemon_threds = True class IPTVserver(BaseHTTPRequestHandler): def send_response(self, code, message = None): self.log_request(code) self.wfile.write('%s %d %s ' % (self.protocol_version,code, message)) self.wfile.flush() def do_HEAD(self, contype, lenght = None): self.send_response(200,'OK') self.send_header('Server', sett.nserver) self.send_header('Content-Type', contype) self.send_header('Date', self.date_time_string()) if lenght: self.send_header('Content-lenght', lenght) self.end_headers() def do_GET(self): path = self.path.lstrip('/') expansion = self.get_expansion(path) self.send_content(path, expansion)
@jonathansimmons2863
@jonathansimmons2863 6 жыл бұрын
How to run this?
@animemaniaticos2483
@animemaniaticos2483 6 жыл бұрын
you can open it on cmd as nameofyourfile.py
@trollnot5526
@trollnot5526 5 жыл бұрын
I saw in another comment to use atom
@maramismail432
@maramismail432 5 жыл бұрын
@@animemaniaticos2483 I tried it not working, can I show a picture for clarification? Please
@skywalker778
@skywalker778 6 жыл бұрын
got it, but images wont show up..
@Victor_Marius
@Victor_Marius 5 жыл бұрын
class Serv(BaseHTTPRequestHandler): def do_GET(self): print('...received url: ', self.path, ' ') filePath = '/index.html' if self.path == '/' else self.path filePath = filePath.replace('%20', ' ') # this line allows files and directories which contains spaces in their names try: with open(filePath[1:], 'rb') as file: # this line open the file to be read as binary (done by 'rb'), images has to be read as binary fileContent = file.read() self.send_response(200) except: fileContent = bytes('File not found!', 'utf-8') self.send_response(404) self.end_headers() self.wfile.write(fileContent)
@APC9906
@APC9906 5 жыл бұрын
Assuming this is Python 3
@MohamedAhmed-op3lu
@MohamedAhmed-op3lu 4 жыл бұрын
it doesn't work with me, always gives me 404 file not found can you help please?
@Ss-wz1op
@Ss-wz1op 4 жыл бұрын
U should create ur file bro using . html extensiom
@Ftoy-OG
@Ftoy-OG 3 жыл бұрын
the program dosent find the file you trying to send /[example.html] wouldnt be found if it wasnt next to the executable mainexample.py
@caio-jl6qw
@caio-jl6qw 5 жыл бұрын
i like your accent!
@hizokadarkwolf
@hizokadarkwolf 5 жыл бұрын
super
@jansabana
@jansabana 4 жыл бұрын
I like your accent !
@irislu815
@irislu815 5 жыл бұрын
i fixed it as well ! yeah
@olegmaz3969
@olegmaz3969 5 жыл бұрын
I get error: Error code: 501 Message: Unsupported method ('GET'). Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation.
@ladygaga7310
@ladygaga7310 3 жыл бұрын
so am i
@frotribe4329
@frotribe4329 3 жыл бұрын
You should write do_Get as do_GET
@frotribe4329
@frotribe4329 3 жыл бұрын
That's what solved my problem
@Cocinaconparrilla
@Cocinaconparrilla 5 жыл бұрын
i just PHP include " "; it the file and it works...
@DominicVictoria
@DominicVictoria 4 жыл бұрын
How to stop server
@williamknight2433
@williamknight2433 3 жыл бұрын
but how come i can't access my site on other devices ?
@clodman84
@clodman84 3 жыл бұрын
You are hosting is localhost, that's why
@knifebosstutorials
@knifebosstutorials 6 жыл бұрын
When would this be better than using like apache?
@wneild5
@wneild5 6 жыл бұрын
Knife Boss maybe for development purposes so that rather than installing and setting up a whole web server like apache, you could use a small lightweight python server.
@lwh8652
@lwh8652 6 жыл бұрын
How easily could this type of simple server be hacked?
@danielgorgis2616
@danielgorgis2616 5 жыл бұрын
extremely easily
@danielgorgis2616
@danielgorgis2616 5 жыл бұрын
if you don't work you dependencies correctly, it's almost welcoming you to hack it
@Fallenskate069
@Fallenskate069 5 жыл бұрын
@@danielgorgis2616 its hosted locally. It would only be easy if the hacker had direct access to your computer.
@evanwilliams1199
@evanwilliams1199 4 жыл бұрын
@@danielgorgis2616 If I wanted to host a small website for an hour and only have a couple friends join it, how could I make this webserver more secure?
@Victor_Marius
@Victor_Marius 5 жыл бұрын
And, now, how do you stop it?
@drewbutler1326
@drewbutler1326 3 жыл бұрын
Yes
@Victor_Marius
@Victor_Marius 3 жыл бұрын
@@drewbutler1326 Ctrl+C will do it, but better is to have a special route which will stop serving but be able to do something extra in the end
@syror5000
@syror5000 4 жыл бұрын
Clapp clapp Thanks!
@theinthanhlan3582
@theinthanhlan3582 2 жыл бұрын
How to host globally
@gyanuchaulagain2062
@gyanuchaulagain2062 6 жыл бұрын
Make video about how to make complex ecommerce site like Amazon and ebay
@jacksonabernathy1683
@jacksonabernathy1683 6 жыл бұрын
Gyanu Chaulagain *videos
@user-rv5qf1ud6j
@user-rv5qf1ud6j 4 жыл бұрын
Just use website builders like weebly, wordpress etc. Even if you can code there is no point in struggling nowadays. Above mentioned websites already have ecommerce worked out for you.
@undefinedchannel9916
@undefinedchannel9916 4 жыл бұрын
@@user-rv5qf1ud6j eww no, stick to html and css and DEFINITELY php
@justviren7855
@justviren7855 5 жыл бұрын
its not working
@Outtapocket206
@Outtapocket206 4 жыл бұрын
Can someone change html of Facebooks web server?
@red1monster_
@red1monster_ 4 жыл бұрын
Yikes
@user-rv5qf1ud6j
@user-rv5qf1ud6j 4 жыл бұрын
This is pure comedy.
@undefinedchannel9916
@undefinedchannel9916 4 жыл бұрын
​@@user-rv5qf1ud6j tru. Technically they could, if they broke into the server room and replaced the .html file
@tusharniras
@tusharniras 3 жыл бұрын
65 dislikes by Flask users
@teamplus9362
@teamplus9362 4 жыл бұрын
can I make it public ?
@undefinedchannel9916
@undefinedchannel9916 4 жыл бұрын
port forwarding, go to your router page and forward port 80 on the device you host the website on. then get your ip and tell someone to connect to it ;D
@teamplus9362
@teamplus9362 4 жыл бұрын
@@undefinedchannel9916 thanks! (:
@undefinedchannel9916
@undefinedchannel9916 4 жыл бұрын
@@teamplus9362 np Btw on some routers, the page is 10.0.0.1
@teamplus9362
@teamplus9362 4 жыл бұрын
@@undefinedchannel9916 and the password I put is the one that connects to my router?
@undefinedchannel9916
@undefinedchannel9916 4 жыл бұрын
@@teamplus9362 usually no, what's your wifi company?
@tosindaudu6595
@tosindaudu6595 6 жыл бұрын
This just a localhost client server not a web server b\c you need a public domain
@albertomancino4166
@albertomancino4166 5 жыл бұрын
​@Tonio Your internet service provider always change your IP, it's called dynamic IP. That IP is the only public IP in home networks, and is the router IP. Other machines inside your private home network have a private IP, which means that only the participant to the network can connect to the machine with that address. Sooo you need to configure your router to handle this, cause your router is your "window on the net" :)
@peshotod
@peshotod Жыл бұрын
For some reason does not work
@minimoon300
@minimoon300 5 жыл бұрын
villager news
@Fivisom
@Fivisom 4 жыл бұрын
I’m from Northern Ireland!
@franceleeparis37
@franceleeparis37 5 жыл бұрын
Lost me...🤔
@David-nn1cf
@David-nn1cf 4 жыл бұрын
No offense, but you didn't make a web server, you just used a pre-existing one from a library.
@subcriberswithoutvideoch-br8cs
@subcriberswithoutvideoch-br8cs 5 жыл бұрын
Who is here to make minecraft server?
@themindstorm9947
@themindstorm9947 5 жыл бұрын
Can you?
@TheLichKng64
@TheLichKng64 5 жыл бұрын
not me but you got my like for the MC commend XD
@anshumishra9368
@anshumishra9368 3 жыл бұрын
pahli baat toh ad bahut ghatiya tha kyuki usne apna in kam 2 lakh bataya per sala 7 lakh kamata hai aur hum log ko 1 lakh ka job dilayega
@Techie-in-Cloud
@Techie-in-Cloud 5 жыл бұрын
Fake accent
Making a BLOCKCHAIN in PYTHON WITH MINING!
6:40
howCode
Рет қаралды 91 М.
Simple HTTP Server in Python
17:56
NeuralNine
Рет қаралды 178 М.
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 15 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 49 МЛН
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 4,3 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 25 МЛН
Web Server Concepts and Examples
19:40
WebConcepts
Рет қаралды 237 М.
you STILL need a website RIGHT NOW!! (yes, even in 2024)
19:15
NetworkChuck
Рет қаралды 384 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 232 М.
What is a Server? (Deepdive)
17:51
LiveOverflow
Рет қаралды 171 М.
Tmux has forever changed the way I write code.
13:30
Dreams of Code
Рет қаралды 950 М.
Making Minimalist Web Server in C on Linux
10:23
Nir Lichtman
Рет қаралды 238 М.
Deploying a Simple Python Web Server
14:23
Akamai Developer
Рет қаралды 43 М.
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 15 МЛН