Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: How to connect to a website? Date: Mon, 22 Apr 2013 16:38:47 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 29 Message-ID: References: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1366648727 21179 166.84.1.1 (22 Apr 2013 16:38:47 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 22 Apr 2013 16:38:47 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:44097 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 > 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"