Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; '21,': 0.07; 'socket': 0.07; 'sys': 0.07; 'filename': 0.09; 'sake': 0.09; 'sys,': 0.09; 'subject:How': 0.10; "'c'": 0.16; '1024)': 0.16; 'buffer,': 0.16; 'file-like': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'port))': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'writable': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'command': 0.22; 'import': 0.22; 'rules': 0.22; 'print': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'error': 0.23; 'handling': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'lines': 0.31; "skip:' 10": 0.31; 'subject:website': 0.31; 'file': 0.32; 'display': 0.35; 'received:84': 0.35; 'subject:?': 0.36; 'hi,': 0.36; 'step': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'read': 0.60; "you're": 0.61; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=JsTI8qIC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=7AxPfEIvyrUA:10 a=IUSJIaeFTwQA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=gjWesLB0Yr8A:10 a=6iOXziZjAAAA:8 a=BQgw7CQBsvCSQRUIiQcA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Mon, 22 Apr 2013 17:40:19 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to connect to a website? References: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> In-Reply-To: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366648821 news.xs4all.nl 2233 [2001:888:2000:d::a6]:57373 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44098 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 > 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]