[Pythonmac-SIG] Problems with urllib?

Laurent Pierron Laurent.Pierron@loria.fr
Tue, 22 Jan 2002 09:32:37 +0100


Yair Benita wrote:

> I try to run a simple query using urllib. For example:
> 
> import urllib
> 
> x=urllib.urlopen("http://www.ebi.ac.uk/cgi-bin/emblfetch?db=embl&format=fast
> a&style=raw&id=AB002378")
> print x.read()
> 

I had the same problem and I do that :

================================================
import urllib

x=urllib.urlopen("http://www.ebi.ac.uk/cgi-bin/emblfetch?db=embl&format=fasta&style=raw&id=AB002378")
data = x.read()

while data:
     print data
     data = x.read()
================================================


Another solution could be :


===========================================
import urllib

(file,headers)=urllib.urlretrieve("http://www.ebi.ac.uk/cgi-bin/emblfetch?db=embl&format=fasta&style=raw&id=AB002378")

x=open(file)
print x.read()
x.close()

import os
os.remove(file)

=============================================


-- 
Laurent PIERRON