6

我正在尝试使用 Entrez 将发布数据导入数据库。搜索部分工作正常,但是当我尝试解析时:

from Bio import Entrez

def create_publication(pmid):

    handle = Entrez.efetch("pubmed", id=pmid, retmode="xml")
    records = Entrez.parse(handle)
    item_data = records.next()
    handle.close()

...我收到以下错误:

解析中的文件“/venv/lib/python2.7/site-packages/Bio/Entrez/Parser.py”,第 296 行引发 ValueError(“XML 文件不代表列表。请使用 Entrez.read 而不是 Entrez .parse") ValueError:XML 文件不代表列表。请使用 Entrez.read 而不是 Entrez.parse

这段代码直到几天前才有效。任何想法这里可能出了什么问题?

此外,查看源代码(http://biopython.org/DIST/docs/api/Bio.Entrez-pysrc.html)并尝试遵循列出的示例,会给出相同的错误:

from Bio import Entrez 
Entrez.email = "Your.Name.Here@example.org"
handle = Entrez.efetch("pubmed", id="19304878,14630660", retmode="xml")    
records = Entrez.parse(handle) 
for record in records: 
    print(record['MedlineCitation']['Article']['ArticleTitle']) 
handle.close()
4

1 回答 1

3

如其他评论和GitHub 问题中所述,该问题是由 NCBI Entrez Utilities Developers 故意更改引起的。如 Jhird 在此问题中所述,您可以将代码更改为以下内容:

from Bio import Entrez 
Entrez.email = "Your.Name.Here@example.org"
handle = Entrez.efetch("pubmed", id="19304878,14630660", retmode="xml")  

records = Entrez.read(handle)      # Difference here
records = records['PubmedArticle'] # New line here  

for record in records: 
    print(record['MedlineCitation']['Article']['ArticleTitle']) 
handle.close()
于 2017-02-03T02:04:43.053 回答