Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44097
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to connect to a website? |
| Date | 2013-04-22 16:38 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <kl3p2n$klr$1@reader1.panix.com> (permalink) |
| References | <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> |
In <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> webmaster@terradon.nl writes:
> 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
I haven't worked with the socket library, but I think this error is because
you specified a mode of 'r' when calling makefile(). fileobj is read-only,
and you're trying to write to it.
If you just want to connect to a website, try using the urllib2 module
instead of socket. It's higher-level and handles a lot of details for
you. Here's an example:
import urllib2
request = urllib2.Request('http://www.voidspace.org.uk')
response = urllib2.urlopen(request)
content = response.readlines()
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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