[Tutor] Help error 504
Timo
timomlists at gmail.com
Tue Aug 25 12:48:43 CEST 2015
Op 25-08-15 om 02:08 schreef Gonzalo V:
> how can simulate or emulate an error 504?
I think using a site like http://httpbin.org/ is a bit easier than mock
or your own server.
Just change your request url to:
http://httpbin.org/status/504
Timo
> i am new in python and its very intuitive! but i am in problems with that
> code.
>
> i wrote this code and it cant handle 504 error:
> import urllib.request
> import urllib.error
> from bs4 import BeautifulSoup
> import re, csv
> from FuncionCsv import LlenarCsv
>
>
>
> fhand=open('isbn.txt')
> #csvfile=open('ResultadoScrapping.csv', 'w', newline='')
> for line in fhand:
> req=urllib.request.urlopen('XXXXXXXX'+line)
> resp=req.read()
> soup=BeautifulSoup(resp,'html.parser')
> try:
> origen=soup.find(string=re.compile("Origen:
> ")).find_next().get_text()
> nombre=soup.find(name="h1",itemprop="name").get_text()
> precioAhora=soup.find(name="p",class_="precioAhora").get_text()
> d=soup.find(name="p",class_="stock").get_text()
> disp=d.split()
> except AttributeError:
> disp="no encontrado"
> nombre=''
> origen=''
> precioAhora=''
> except urllib.error.HTTPError as e:
> if e.getcode()==504:
> disp = "sin respuesta del servidor"
> print (e.getcode(),disp)
> csvfile.close()
>
> print(line,nombre,origen,precioAhora,disp)
> line1=line.split()
> LlenarCsv('Resultado.csv',line1,nombre,origen,precioAhora,disp)
>
> please help!
>
>
>
>
> Saludos,
> Gonzalo
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list