Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34457

python 3.3 urllib.request

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 <steevechailloux@gmail.com>
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; '-&gt;': 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 <steevechailloux@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.605.1354884780.29569.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

python 3.3 urllib.request Steeve C <steevechailloux@gmail.com> - 2012-12-07 13:52 +0100
  Re: python 3.3 urllib.request Hans Mulder <hansmu@xs4all.nl> - 2012-12-07 18:27 +0100
    Re: python 3.3 urllib.request Terry Reedy <tjreedy@udel.edu> - 2012-12-08 01:20 -0500
      Re: python 3.3 urllib.request Hans Mulder <hansmu@xs4all.nl> - 2012-12-08 13:21 +0100

csiph-web