[Biopython] Problem using Entrez with Python 3.2

Wibowo Arindrarto w.arindrarto at gmail.com
Wed Dec 19 14:25:46 UTC 2012


Hi Nicolas,

Glad to hear that :). I have to note that what I proposed was a
workaround for a bug as your initial code was meant to work without
any errors. We've recently applied an initial fix and your prior code
should be working fine in the next Biopython release.

If you really need the fix now (and are feeling a bit adventurous) you
can try installing our development version from GitHub:
http://github.com/biopython/biopython. We have a quick draft guide on
working with git here:
http://biopython.org/wiki/GitUsage

cheers,
Bow


On Wed, Dec 19, 2012 at 7:13 AM, Nicolas Joannin
<nicolas.joannin at gmail.com> wrote:
> Hi Bow,
>
> Thanks a million for your answer!
> It is very clear and pedagogical; I appreciate that a lot!
> Works like a charm ;)
>
> Best regards,
> Nicolas
>
>
>
> Nicolas Joannin, Ph.D.
> Bioinformatics Center
> Kyoto University, Uji campus, Japan
>
>
>
>
> On Sat, Dec 15, 2012 at 2:58 PM, Wibowo Arindrarto <w.arindrarto at gmail.com>
> wrote:
>>
>> Hi Nicolas,
>>
>> AFAIK, the Entrez XML parser requires bytes instead of strings. The
>> distinction matters in Python 3, so what you need to do is to convert
>> your string stream into a byte stream. To do so, you need to add a new
>> import:
>>
>> from io import BytesIO
>>
>> and replace the last line with these:
>>
>> bytehandle = BytesIO(bytes(handle.read(), 'utf-8'))  # utf-8 or any
>> other encoding you want
>> record = Entrez.read(bytehandle)
>>
>> We're basically reading the string, convert it to bytes, and create a
>> buffered bytes I/O that Entrez.read expects.
>>
>> Alternativey, you can also read the handle into a file first, and open
>> it in binary mode:
>>
>> with open('outfile.xml', 'w') as outfile:
>>     outfile.write(handle.read())
>>
>> with open('outfile.xml', 'rb') as sourcefile:
>>     record = Entrez.read(sourcefile)
>>
>> Hope that helps :),
>> Bow
>>
>> On Tue, Dec 11, 2012 at 2:15 AM, Nicolas Joannin
>> <nicolas.joannin at gmail.com> wrote:
>> > Hello,
>> >
>> > I'm having problems when trying to use Bio.Entrez with Python 3.2.
>> > I get the following error message:
>> >
>> >>>> from Bio import Entrez
>> >>>> Entrez.email='my at email.address'
>> >>>> handle=Entrez.esearch(db='nuccore',term='36329')
>> >>>> record=Entrez.read(handle)
>> > Traceback (most recent call last):
>> >   File "<stdin>", line 1, in <module>
>> >   File
>> >
>> > "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/Bio/Entrez/__init__.py",
>> > line 351, in read
>> >     record = handler.read(handle)
>> >   File
>> >
>> > "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/Bio/Entrez/Parser.py",
>> > line 169, in read
>> >     self.parser.ParseFile(handle)
>> > TypeError: read() did not return a bytes object (type=str)
>> >
>> > Any comment, suggestion or help would be greatly appreciated!
>> > Best regards,
>> >
>> > Nicolas
>> > _______________________________________________
>> > Biopython mailing list  -  Biopython at lists.open-bio.org
>> > http://lists.open-bio.org/mailman/listinfo/biopython
>
>



More information about the Biopython mailing list