PY4E - HTTP (Chapter 12 Part 3)
www.py4e.com - Python for Everybody: Exploring Data in Python 3.0
Please visit the web site to access a free textbook, free supporting materials, as well as interactive exercises.
www.py4e.com - Python for Everybody: Exploring Data in Python 3.0
Please visit the web site to access a free textbook, free supporting materials, as well as interactive exercises.
Пікірлер: 39
For anyone else trying to run this code, the following line needs to be changed: From: cmd = 'GET data.pr4e.org/romeo.txt HTTP/1.0 ' To: cmd = 'GET data.pr4e.org/romeo.txt HTTP/1.0 ' Otherwise, you will get an error 400 returned instead of the expected text.
@danielpetrusevski1295
6 жыл бұрын
I've used this change but I still get 'error 400'
@FixedITyesterday
6 жыл бұрын
Found the answer after some Googling. Can only assume that the web server needs new lines to be both line_feed( ) and carriage_return( ) characters in the command string instead of just line_feed. The following video in the series also mentions this - which I saw afterwards.
@FixedITyesterday
6 жыл бұрын
Just looked it up, it required as part of the HTTP syntax, see en.wikipedia.org/wiki/Hypertext_Transfer_Protocol under Message format for details.
@epistemophile4420
3 жыл бұрын
For those who want to know, " " is the class Unix/Linux style for the new line. " " is the default Windows style for line separator. " " is a classic Mac style for line separator.
@phatcat7924
2 жыл бұрын
Thanks a lot. It worked
Reminder for people that you need to change the following line: FROM: cmd = 'GET data.pr4e.org/romeo.txt HTTP/1.0 '.encode() TO: cmd = 'GET data.pr4e.org/romeo.txt HTTP/1.0 '.encode() It required as part of the HTTP syntax, see en.wikipedia.org/wiki/Hypertext_Transfer_Protocol under Message format for details. Can only assume that the web server needs new lines to be both line_feed( ) and carriage_return( ) characters in the command string instead of just line_feed.
@swaggedout
11 ай бұрын
Thank you for coming back three years later and commenting it again, was really disappointed when I saw it didn't run. You have a great day!
@bobanmilisavljevic7857
8 ай бұрын
Thank you!!!! 🥳👍
As of the ending of this video I now believe you. Python really is for everybody!
nice ending :D
These videos deserves more veiws
I wasn't ready for that outro! 😂🤟
@tlhogid663
Жыл бұрын
Agreed! 😂
What could be the problem? When I get romeo.txt it splits on the 4th line, so I get back: But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already s ick and pale with grief When I set the buffer size from 512 to 1024 it printed out correctly. Any ideas? EDIT: I figured it out, the buffer gets filled with 512 bytes with the metadata + the file contents up to that point, in a later video I saw the print statement had the end = "" parameter which makes it work with the 512 byte buffer. The way I figured it out was I removed the decode() method from the data variable and then when I ran the code it was clearly visible that the line is split and when I counted the bytes there were about 512. I am glad I figured this out on my own ☺
if i wanted to do this on a https website, how would i go about doing that?
python (socket)
Why do we get the output only as: But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief Even increasing the number of characters from 512 to 8000, I still get the same. Why is that so?
@milaloup
2 жыл бұрын
That is all of the text in the file. There simple isn't more in it.
Caotic vibe
I get "Your browser sent a request that this server could not understand." message and did not get romeo.txt. Should I install telnet kinda things or something?
@reneelague
5 жыл бұрын
I'm getting a 400 Bad Request as well. Maybe the file isn't there any more or something??
@johnrogers3315
5 жыл бұрын
use cmd = 'GET data.pr4e.org/romeo.txt HTTP/1.0 ' .encode() then; the sockets react at machine speed, if it doesn't receive instruction very quickly it terminates. The code works when the kernel has been refreshed and then all cells are run as 'run all' (or whichever IDE command you use).
@CarolinaNT
5 жыл бұрын
@@johnrogers3315 thanks!
@babadepou
5 жыл бұрын
@@johnrogers3315 Hey! Thanks for your answer it helped me too! I was wondering what is the function of the you've added to the command. Thanks
@pvperez1
5 жыл бұрын
@@johnrogers3315 Thanks! That worked for me
For some reason I cannot see the metadata when I do this
@ChuckSeverance
Жыл бұрын
More and more servers do not support the HTTP 1.1 protocol you you can't always reproduce these examples perfectly.
Is it me or some hacker checked that texted file and messed up the last sentence with? “Who is already s ick and pale with grief”
@tlhogid663
Жыл бұрын
No - I think there might be something wrong with your code
lol