masklinn í dag viðrar vel til loftárása | erwan83 a écrit :
Bonjour. j'ai réfléchi (si si )
Code :
req = urllib2.Request(ADRESSE, None, headers) try: response = urllib2.urlopen(req) except (IOError), eObject: print 'E R R E U R D E N T R E E S O R T I E - Erreur [%s]' % eObject fich = open('d:\ERREUR_ACCES.TXT','a') fich.write(ADRESSE) fich.write("\n" ) fich.close() except (ValueError), eObject: print 'E R R E U R D E V A L E U R - Erreur [%s]' % eObject fich = open('d:\ERREUR_ACCES.TXT','a') fich.write(ADRESSE) fich.write("\n" ) fich.close() except: print 'E R R E U R A U T R E' fich = open('d:\ERREUR_ACCES.TXT','a') fich.write(ADRESSE) fich.write("\n" ) fich.close() else: TXTWEB='' if response: try: TXTWEB = response.read()
|
|
The fuck's that shit ![[:pingouino] [:pingouino]](https://forum-images.hardware.fr/images/perso/pingouino.gif) Faut se calmer sur les majuscules et les messages d'erreur débiles un peu, et foutre des try/except partout aussi ![[:pingouino] [:pingouino]](https://forum-images.hardware.fr/images/perso/pingouino.gif) Et pourquoi tu as besoin de créer une Request exactement, t'as des headers custom à monter ![[:pingouino dei] [:pingouino dei]](https://forum-images.hardware.fr/images/perso/pingouino dei.gif) erwan83 a écrit :
certaines URL ne répondent pas ou bien ont un comportement bizarre (sous le navigateur, l'icone tourne, tourne, tourne et jamais aucun résultat n'est renvoyé. donc mon prog lui aussi... tourne, tourne, tourne... et il attend que je revienne le voir huit heures après pour me dire qu'il est toujours en train de lire l'adresse je ne sais pas comment gérer cette exception.
|
C'est pas une exception. Dans Python 2.6, urlopen prend un argument timeout comme indiqué dans la doc. C'est le temps qu'il va passer à attendre la réponse
Message édité par masklinn le 29-07-2010 à 11:46:02 ---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
|