Encoding problems with DCOracle2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Timo Virkkala

    Encoding problems with DCOracle2

    I'm having some trouble with Python2.2 and DCOracle2. I'm successfully
    executing a query, and getting the result I'm hoping for - with an added
    bonus of some interesting encoding. The beginning of the result set I
    get looks like this:

    [['\x00A\x001', '\x00M\x00i\x00 k\x00e\x00
    \x00P\x00o\x00r \x00t\x00n\x00o \x00y', None, None,
    '\x00d\x00r\x00 u\x00m\x00s'], ...

    So, where are those \x00 -characters coming? It should read:

    [['A1', 'Mike Portnoy', None, None, 'drums'], ...

    (...it's an artist database, and that's Dream Theater's drummer..)

    --
    Timo Virkkala | wt@nic.fi

    "In the battle between you and the world, bet on the world."

  • Peter Otten

    #2
    Re: Encoding problems with DCOracle2

    Timo Virkkala wrote:
    [color=blue]
    > I'm having some trouble with Python2.2 and DCOracle2. I'm successfully
    > executing a query, and getting the result I'm hoping for - with an added
    > bonus of some interesting encoding. The beginning of the result set I
    > get looks like this:
    >
    > [['\x00A\x001', '\x00M\x00i\x00 k\x00e\x00
    > \x00P\x00o\x00r \x00t\x00n\x00o \x00y', None, None,
    > '\x00d\x00r\x00 u\x00m\x00s'], ...
    >
    > So, where are those \x00 -characters coming? It should read:
    >
    > [['A1', 'Mike Portnoy', None, None, 'drums'], ...
    >
    > (...it's an artist database, and that's Dream Theater's drummer..)
    >[/color]

    Seems you are getting unicode from the db. Here's how to convert it to
    latin1:
    [color=blue][color=green][color=darkred]
    >>> unicode('\x00P\ x00o\x00r\x00t\ x00n\x00o\x00y' ,[/color][/color][/color]
    'utf-16-be').encode('la tin1')
    'Portnoy'[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Peter

    Comment

    • Timo Virkkala

      #3
      Re: Encoding problems with DCOracle2

      Peter Otten wrote:[color=blue]
      > Timo Virkkala wrote:[color=green]
      >>I'm having some trouble with Python2.2 and DCOracle2. I'm successfully
      >>executing a query, and getting the result I'm hoping for - with an added
      >>bonus of some interesting encoding. The beginning of the result set I
      >>get looks like this:
      >>
      >>[['\x00A\x001', '\x00M\x00i\x00 k\x00e\x00
      >>\x00P\x00o\x0 0r\x00t\x00n\x0 0o\x00y', None, None,
      >>'\x00d\x00r\x 00u\x00m\x00s'], ...[/color]
      >
      > Seems you are getting unicode from the db. Here's how to convert it to
      > latin1:
      >[color=green][color=darkred]
      > >>>unicode('\x0 0P\x00o\x00r\x0 0t\x00n\x00o\x0 0y', 'utf-16-be').encode('la tin1')[/color][/color]
      > 'Portnoy'[/color]

      Thanks, that solved it! Now, it feels like I'm treating a symptom here,
      not the cause. Is there a way to set the database (Oracle 9i) to send me
      something else than Unicode?

      --
      Timo Virkkala | wt@nic.fi

      "In the battle between you and the world, bet on the world."

      Comment

      Working...