Question: Biopython Entrez.Efetch Problem
0
gravatar for a11msp
8.0 years ago by
a11msp110
European Union
a11msp110 wrote:

Hi everyone,

I'm trying to run an example from the Biopython cookbook and it returns an error. I'm wondering if anything serious has changed in the PubMed API recently...

from Bio import Medline
handle = Entrez.esearch(db="pubmed", term="orchid", retmax=463)
record = Entrez.read(handle)
idlist = record["IdList"]
handle = Entrez.efetch(db="pubmed", id=idlist, rettype="medline", retmode="text")

I'm getting:

HTTPError                                 Traceback (most recent call last)

<ipython console> in <module>()

python-2.7.1-shared/lib/python2.7/site-packages/biopython-1.58-py2.7-linux-x86_64.egg/Bio/Entrez/__init__.pyc in efetch(db, **keywds)
    111     variables = {'db' : db}
    112     variables.update(keywds)
--> 113     return _open(cgi, variables)
    114 
    115 def esearch(db, term, **keywds):

python-2.7.1-shared/lib/python2.7/site-packages/biopython-1.58-py2.7-linux-x86_64.egg/Bio/Entrez/__init__.pyc in _open(cgi, params, post)
    358             handle = urllib2.urlopen(cgi)
    359     except urllib2.HTTPError, exception:
--> 360         raise exception
    361 
    362     return handle

HTTPError: HTTP Error 500: Internal server error

I checked and idlist is, as expected, a list of PubMed IDs as strings, so Entrez.esearch seems to be working.

['22499266', '22496851', '22483052', '22418255', '22415688', '22408409', '22397405', '22391855', '22375900', '22367365', ...]

Would appreciate your help!

entrez biopython pubmed • 4.2k views
ADD COMMENTlink written 8.0 years ago by a11msp110
2
gravatar for Peter
8.0 years ago by
Peter5.8k
Scotland, UK
Peter5.8k wrote:

Which version of Biopython are you using? My hunch would be this FAQ entry from the tutorial - http://biopython.org/DIST/docs/tutorial/Tutorial.html

Why has my script using Bio.Entrez.efetch() stopped working? This could be due to NCBI changes in February 2012 introducing EFetch 2.0. First, they changed the default return modes - you probably want to add retmode="text" to your call. Second, they are now stricter about how to provide a list of IDs – Biopython 1.59 onwards turns a list into a comma separated string automatically.

Try updating your Biopython or using ",".join(idlist) instead.

ADD COMMENTlink written 8.0 years ago by Peter5.8k
1

Bravo, maestro! ",".join(idlist) has solved the problem. Many thanks!

ADD REPLYlink written 8.0 years ago by a11msp110
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1418 users visited in the last hour