문제

I am using the Biopython package, but I am having trouble with one of its functions. I am following the documentation of the package ( here) to the letter:

This is what I have tried:

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

and I get this error

 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.

and so I did what the interpreter recommended and did the following:

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

and this is the error that I got:

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.  

Any idea why this is not working?

도움이 되었습니까?

해결책

I just solved this problem. Basically, after I do

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

and it gives the error, I was directly calling

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

which will not work because it is still in an "error state" so instead declare handle again and it should work like this:

handle = Entrez.einfo(db = "pubmed")
record = Entrez.read(handle, validate = False)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top