Biopython Entrez.read()不起作用

时间:2013-11-27 17:37:43

标签: python biopython

我正在使用Biopython软件包,但我的一个功能遇到了问题。我按照包裹的文件(here)来写信:

这就是我的尝试:

from Bio import Entrez
Entrez.email = "myemail@myuniversity"
handle = Entrez.einfo(db = "pubmed")
record = Entrez.read(handle)

我收到此错误

 File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/Bio/Entrez/__init__.py", line 367, in read
    record = handler.read(handle)
  File "/usr/local/lib/python2.7/dist-packages/Bio/Entrez/Parser.py", line 184, in read
    self.parser.ParseFile(handle)
  File "/usr/local/lib/python2.7/dist-packages/Bio/Entrez/Parser.py", line 300, in startElementHandler
    raise ValidationError(name)
Bio.Entrez.Parser.ValidationError: Failed to find tag 'DbBuild' in the DTD. To skip all tags that are not represented in the DTD, please call Bio.Entrez.read or Bio.Entrez.parse with validate=False.

所以我做了翻译推荐的内容并做了以下事情:

record = Entrez.read(handle, validate = False)

这是我得到的错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/Bio/Entrez/__init__.py", line 367, in read
    record = handler.read(handle)
  File "/usr/local/lib/python2.7/dist-packages/Bio/Entrez/Parser.py", line 194, in read
    raise NotXMLError(e)
Bio.Entrez.Parser.NotXMLError: Failed to parse the XML data (syntax error: line 1, column 0). Please make sure that the input data are in XML format.  

知道为什么这不起作用?

1 个答案:

答案 0 :(得分:2)

我刚刚解决了这个问题。基本上,我做完之后

from Bio import Entrez
Entrez.email = "myemail@myuniversity"
handle = Entrez.einfo(db = "pubmed")
record = Entrez.read(handle)

并且它给出了错误,我直接调用了

record = Entrez.read(handle, validate = False)

哪个不起作用,因为它仍处于“错误状态”,所以改为再次声明句柄,它应该像这样工作:

handle = Entrez.einfo(db = "pubmed")
record = Entrez.read(handle, validate = False)