Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44098
| Date | 2013-04-22 17:40 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: How to connect to a website? |
| References | <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.932.1366648821.3114.python-list@python.org> (permalink) |
On 22/04/2013 17:16, webmaster@terradon.nl wrote:
> Hi,
> i just try to connect to a website, read that page and display the rules get from it.
> Then i get this error message:
>
> File "D:/Python/Py projects/socket test/sockettest.py", line 21, in <module>
> fileobj.write("GET "+filename+" HTTP/1.0\n\n")
> io.UnsupportedOperation: not writable
>
> My code:
>
> # import sys for handling command line argument
> # import socket for network communications
> import sys, socket
>
> # hard-wire the port number for safety's sake
> # then take the names of the host and file from the command line
> port = 80
> host = 'www.xxxxxxxx.nl'
> filename = 'index.php'
>
> # create a socket object called 'c'
> c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> # connect to the socket
> c.connect((host, port))
>
> # create a file-like object to read
> fileobj = c.makefile('r', 1024)
You're creating a file-like object for reading...
>
> # Ask the server for the file
> fileobj.write("GET "+filename+" HTTP/1.0\n\n")
>
...and then trying to write to it.
> # read the lines of the file object into a buffer, buff
> buff = fileobj.readlines()
>
> # step through the buffer, printing each line
> for line in buff:
> print (line)
>
[snip]
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to connect to a website? webmaster@terradon.nl - 2013-04-22 09:16 -0700
Re: How to connect to a website? John Gordon <gordon@panix.com> - 2013-04-22 16:38 +0000
Re: How to connect to a website? webmaster@terradon.nl - 2013-04-22 12:56 -0700
Re: How to connect to a website? MRAB <python@mrabarnett.plus.com> - 2013-04-22 17:40 +0100
csiph-web