[Biopython] Bio.Entrez.epost error with Python 3.2

Peter Cock p.j.a.cock at googlemail.com
Thu Mar 21 10:44:33 UTC 2013


On Thu, Mar 21, 2013 at 8:30 AM, Nicolas Joannin
<nicolas.joannin at gmail.com> wrote:
> Hi everyone,
>
> I am still in need of a fix for this problem...

Is this a new problem which you have not previously reported?

> I have made an attempt at fixing it myself by adding a line of code in
> Bio.Entrez.__init__.py:
>
> At line 451 there is:
>
>     try:
>         if post:
>             #HTTP POST
>             options = options.encode('utf-8') #Line added by Nicolas
>             handle = urllib.request.urlopen(cgi, data=options)
>         else:
>             #HTTP GET
>             cgi += "?" + options
>             handle = urllib.request.urlopen(cgi)
>     except urllib.error.HTTPError as exception:
>         raise exception
>
> In my (limited) testing, it seems to work...
> Would this be suitable?
>
> Best regards,
> Nicolas

Assuming you are running this on Python 3.2, it is likely a
bytes versus unicode issue. I'm guessing, but we'd probably
want something like this to handle both Python 2 and 3
(untested):

from Bio._py3k import _as_byte
...
handle = urllib.request.urlopen(cgi, data=_as_bytes(options))

Could you share an example script (just a few lines) to reproduce
the problem please? And include the error message you get.

Thanks,

Peter



More information about the Biopython mailing list