Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'python3': 0.05; 'skip:+ 80': 0.05; '-*-': 0.07; '__name__': 0.07; 'main()': 0.07; 'skip:\\ 10': 0.07; 'sys,': 0.07; 'try:': 0.07; 'utf-8': 0.07; 'behavior,': 0.09; 'coding:': 0.09; 'plug': 0.09; 'script,': 0.09; 'stderr': 0.09; 'def': 0.10; 'subject:python': 0.11; '%h:%m:%s': 0.16; "'__main__':": 0.16; '(so,': 0.16; '->': 0.16; 'e:\xa0': 0.16; 'example)': 0.16; 'looping': 0.16; 'main():': 0.16; 'skip:m 80': 0.16; 'subject:3.3': 0.16; 'url)': 0.16; 'yield': 0.17; 'import': 0.21; 'connected': 0.24; 'script': 0.24; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'subject:skip:u 10': 0.29; '8bit%:5': 0.29; 'connection': 0.30; 'received:209.85.215.46': 0.30; 'error': 0.30; 'handle': 0.33; 'to:addr:python-list': 0.33; '(with': 0.33; 'skip:& 20': 0.33; 'skip:- 20': 0.34; 'skip:b 20': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'continue': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'skip:p 20': 0.36; '(for': 0.37; 'received:209': 0.37; 'page': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'back': 0.62; 'strange': 0.62; 'behavior': 0.64; 'here': 0.65; 'internet': 0.71; 'cable': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=gDaUOGGyHi3FluUetvwBNs0l+9jnEv3QqqbhmfG7eIE=; b=gKC5YmZqrmPfODUaOrqmHCJ9QOb61vm9gXizNfbRBycg1qcOmkOdTMq1euer8d3INH 8mZ3IxGHukKsk6Yfs2X37ljTnxOD1WsUWkAShkNcRIv8jDG/OlhyR+N7MNyKYcutGgIK 9ReItO7FC7oYg221cusbvIyc+JDpEjOniJ414nqIFHWqv4uUWtYXqIhaQRdlTyR3rGco uSodG/Cc/V1SmhapItfr0VY0VzaDMJKj/liXqDdjK7nY2Qmm6//gu2wlWsHSNdHuKbrT DLAfWfA3DFDm2VmAhiP6aWSmkXUzHnuWZlG7M62Wtb3VWKWd0NOJnYxBjRlEiDi5IFdf XVMw== MIME-Version: 1.0 Date: Fri, 7 Dec 2012 13:52:52 +0100 Subject: python 3.3 urllib.request From: Steeve C To: python-list@python.org Content-Type: multipart/alternative; boundary=f46d0401f91d9d700e04d042b15a X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 116 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354884780 news.xs4all.nl 6889 [2001:888:2000:d::a6]:48260 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34457 --f46d0401f91d9d700e04d042b15a Content-Type: text/plain; charset=ISO-8859-1 hello, I have a python3 script with urllib.request which have a strange behavior, here is the script : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #!/usr/bin/env python3 # -*- coding: utf-8 -*- import urllib.request import sys, time url = 'http://google.com' def make_some_stuff(page, url): sys.stderr.write(time.strftime("%d/%m/%Y %H:%M:%S -> page from \"") + url + "\"\n") sys.stderr.write(str(page) + "\"\n") return True def get_page(url): while 1: try: page = urllib.request.urlopen(url) yield page except urllib.error.URLError as e: sys.stderr.write(time.strftime("%d/%m/%Y %H:%M:%S -> impossible to access to \"") + url + "\"\n") time.sleep(5) continue def main(): print('in main') for page in get_page(url): make_some_stuff(page, url) time.sleep(5) if __name__ == '__main__': main() +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if the computer is connected on internet (with an ethernet connection for example) and I run this script, it works like a charme : - urllib.request.urlopen return the page - make_some_stuff write in stderr - when the ethernet cable is unplug the except block handle the error while the cable is unplug, and when the cable is pluged back urllib.request.urlopen return the page and make_some_stuff write in stderr this is the normal behavior (for me, imho). but if the computer is not connected on internet (ethernet cable unpluged) and I run this script, the except block handle the error (normal), but when I plug the cable, the script continue looping and urllib.request.urlopen never return the page (so, it alway go to the except block) What can I do to handle that ? Thanks Steeve --f46d0401f91d9d700e04d042b15a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable hello,

I have a python3 script with urllib.request which= have a strange behavior, here is the script :

+++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import urllib.request
import sys, time



def make_some_stuff(page, url):
=A0 =A0 sys.s= tderr.write(time.strftime("%d/%m/%Y %H:%M:%S -> page from \"&q= uot;) + url + "\"\n")
=A0 =A0 sys.stderr.write(str= (page) + "\"\n")
=A0 =A0 return True

def get_page(url):
<= div>=A0 =A0 while 1:
=A0 =A0 =A0 =A0 try:
=A0 =A0 =A0 = =A0 =A0 =A0 page =3D urllib.request.urlopen(url)
=A0 =A0 =A0 =A0 = =A0 =A0 yield page

=A0 =A0 =A0 =A0 except urllib.error.URLError as e:
=A0 =A0 = =A0 =A0 =A0 =A0 sys.stderr.write(time.strftime("%d/%m/%Y %H:%M:%S ->= ; impossible to access to \"") + url + "\"\n")
=A0 =A0 =A0 =A0 =A0 =A0 time.sleep(5)
=A0 =A0 =A0 =A0 =A0 =A0 continue

def main():<= /div>
=A0 =A0 print('in main')
=A0 =A0 for page in ge= t_page(url):
=A0 =A0 =A0 =A0 make_some_stuff(page, url)
=A0 =A0 =A0 =A0 time.sleep(5)

if __name__ =3D=3D '__main__':
=A0 = =A0 main()
++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++

if the compu= ter is connected on internet (with an ethernet connection for example) and = I run this script, it works like a charme :
-=A0urllib.request.urlopen return the page
-=A0make_some_stu= ff write in stderr
- when the ethernet cable is unplug the except= block handle the error while the cable is unplug, and when the cable is pl= uged back=A0urllib.request.urlopen return the page and=A0make_some_stuff wr= ite in stderr

this is the normal behavior (for me, imho).
<= br>
but if the computer is not connected on internet (ethernet ca= ble unpluged) and I run this script, the except block handle the error (nor= mal), but when I plug the cable, the script continue looping and=A0urllib.r= equest.urlopen never return the page (so, it alway go to the except block)<= /div>

What can I do to handle that ?

Thanks

Steeve
--f46d0401f91d9d700e04d042b15a--