[Python-es] obtener tamaño fichero en URL

Daniel Garcia dani en danigm.net
Mar Feb 7 23:01:10 CET 2012


Lo mismo con las librerías estandar:

import sys
if sys.version_info.major == 3:
    import http.client as httplib
else:
    import httplib

c = httplib.HTTPConnection("mirror.aarnet.edu.au")
c.request("GET", "/pub/archlinux/iso/2011.08.19/archlinux-2011.08.19-core-dual.iso")
response = c.getresponse()
size = response.getheader('Content-Length')

On Tue, Feb 07, 2012 at 10:12:13PM +0100, Andrey Antoukh wrote:
> Como ya he dicho, se puede instalar desde pypi.
> Y no. no viene por defecto en python. Con las bibliotecas estandar tambien
> hay maneras de hacerlo pero son  mucho mas laboriosas.
> 
> Andrei.
> 
> El 7 de febrero de 2012 16:07, Julian A. Charon Macias <
> julianch en fam.cug.co.cu> escribió:
> 
> > ---------- Mensaje Original ----------
> > A: Julian A. Charon Macias (julianch en mail.python.org)
> > De: Andrey Antoukh (andsux en gmail.com)
> > Asunto: [***SPAM*** Score/Req: 05.70/5.0] Re: [Python-es] obtener tamaño
> > fichero en URL
> > Fecha: 7/2/2012 9:47:26p
> >
> > [niwi en vaio.niwi.be][~]% python2
> > Python 2.7.2 (default, Nov 21 2011, 17:25:27)
> > [GCC 4.6.2] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >  >>> import requests
> > >>> requests.head
> > <function head at 0x15ea1b8>
> > >>> response = requests.head("
> > http://mirror.aarnet.edu.au/pub/archlinux/iso/2011..08.19/archlinux-2011.08.19-core-dual.iso
> > ")
> >  >>> response.headers
> > {'last-modified': 'Fri, 19 Aug 2011 10:24:52 GMT', 'content-length': '
> > 705691648', 'etag': '"501df5-2a100000-4aad923cb6500"', 'date': 'Tue, 07
> > Feb 2012 20:45:27 GMT', 'accept-ranges': 'bytes', 'content-type':
> > 'application/octet-stream', 'server': 'Apache/2.2.3 (Red Hat)'}
> >  >>> int(response.headers['content-length'])/1024.0/1024.0
> > 673.0
> >
> > Creo que con esto podria bastarte.La biblioteca que uso es requests.
> > Puedes instalarla desde pypi.
> >
> > El día 7 de febrero de 2012 15:34, Julian A. Charon Macias <
> > julianch en fam.cug.co.cu> escribió:
> >  > Un saludo, como puedo obtener el tamaño(ej. 40 Mb)  de un fichero que
> > este publicado en una direccion URL, mediante Python.
> > > creo que utilizando el modulo URLLIB, pero no veo como.
> > >
> > >
> > >
> >  >
> >  >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Lic. Julián A. Charón Macias
> > > Tel.  : 0294436
> > > A legendary Informatic
> > >
> > >
> > >
> >  >
> > >
> > > UNIVERSIDAD DE GUANTÁNAMO
> > >
> > >
> > > _______________________________________________
> > > Python-es mailing list
> > > Python-es en python.org
> >  > http://mail.python.org/mailman/listinfo/python-es
> > > FAQ: http://python-es-faq.wikidot.com/
> >
> >
> >
> > --
> > Andrei Antoukh - <niwi en niwi.be>
> > http://www.niwi..be/page/about/
> > http://www.kaleidos.net/A5694F/
> >
> > "Linux is for people who hate Windows, BSD is for people who love UNIX"
> > "Social Engineer -> Because there is no patch for human stupidity"
> >
> >
> >
> > Pero... esta biblioteca no viene de facto con Python?
> > Probe pero no vi resultados, me arroja mensaje que el modulo no existe,
> > estoy usando Python 2.7.2 sobre win2.
> >
> > alguna idea?
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > Lic. Julián A. Charón Macias
> > Tel.  : 0294436
> > A legendary Informatic
> >
> >
> >
> >
> >
> > UNIVERSIDAD DE GUANTÁNAMO
> >
> >
> > _______________________________________________
> > Python-es mailing list
> > Python-es en python.org
> > http://mail.python.org/mailman/listinfo/python-es
> > FAQ: http://python-es-faq.wikidot.com/
> >
> 
> 
> 
> -- 
> Andrei Antoukh - <niwi en niwi.be>
> http://www.niwi.be/page/about/
> http://www.kaleidos.net/A5694F/
> 
> "Linux is for people who hate Windows, BSD is for people who love UNIX"
> "Social Engineer -> Because there is no patch for human stupidity"

> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/


-- 
Daniel Garcia 0034 668 810 742
It's not magic, it's wadobo!
http://wadobo.com
------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: no disponible
Type: application/pgp-signature
Size: 198 bytes
Desc: no disponible
URL: <http://mail.python.org/pipermail/python-es/attachments/20120207/b13e8bc4/attachment.pgp>


Más información sobre la lista de distribución Python-es