XMLRPCServer issues

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

    #1

    XMLRPCServer issues

    Hi,

    I had some issues with XMLRPCServer and I try to validate my
    workaround.

    My first try was this (somewhat self explaining code):

    from DocXMLRPCServer import DocXMLRPCServer
    from cx_Oracle import connect

    def get_task_list(u ser):
    sql = """
    select ISS.ISS_ISSUE_N UMBER
    , ISS.ISS_DESCRIP TION
    , ISS.C_PC_ISS_ST ATUS
    , ISS.ISS_IN_WORK
    , ISS.PC_ISSUES_I D
    , DES.GCDTEXT1
    from ...
    where ...
    """
    con = connect('DEVELO P/DEVELOP@DEV2003 ')
    cur = con.cursor()
    cur.execute(sql , USE_NAME = user.upper())
    result = cur.fetchall()
    cur.close()
    con.close()
    return result

    server = DocXMLRPCServer (("localhost" , 8000))
    server.register _function(get_t ask_list)
    server.serve_fo rever()


    But I had 2 errors with this code:
    -PC_ISSUES_ID column could be an integer of 12 digits but the XML
    generator only allow 2L**31-1 long integer, so I had an
    Overflowexcepti on: long int exceeds XML-RPC.
    -Text columns (like ISS_DESCRIPTION ) could contains non ascii char.
    (éàç) but the server doesn't allow to specify the encoding to use
    for the XML, so parser error on non-ascii char. on the client side
    (ExpatError: not well-formed (invalid token)).

    My working code with workarounds for these issues is:

    from DocXMLRPCServer import DocXMLRPCServer
    from cx_Oracle import connect

    #increase MAXINT constant to allow 12 digits integer for PC_ISSUES_ID
    #(long int exceeds XML-RPC exception)
    import xmlrpclib
    xmlrpclib.MAXIN T = 999999999999

    def get_task_list(u ser):
    sql = """
    select ISS.ISS_ISSUE_N UMBER
    , ISS.ISS_DESCRIP TION
    , ISS.C_PC_ISS_ST ATUS
    , ISS.ISS_IN_WORK
    , ISS.PC_ISSUES_I D
    , DES.GCDTEXT1
    from ...
    where ...
    """
    con = connect('DEVELO P/DEVELOP@DEV2003 ')
    cur = con.cursor()
    cur.execute(sql , USE_NAME = user.upper())
    result = cur.fetchall()
    cur.close()
    con.close()
    #convert string column to unicode (XML generator does not use
    # encoding so string must be UTF8 or unicode)
    result =[list(row) for row in result]
    for row in result:
    for count, x in enumerate(row):
    if isinstance(x, str):
    row[count] = x.decode('cp125 2')
    return result

    server = DocXMLRPCServer (("localhost" , 8000))
    server.register _function(get_t ask_list)
    server.serve_fo rever()


    But it seems to me not very clean, especially the MAXINT hack.
    Has anyone a better solution ?

  • Brian Quinlan

    #2
    Re: XMLRPCServer issues

    1. Is there on option to get cx_Oracle to return string data as unicode
    rather than strings objects? XML-RPC aside, dealing with unicode objects
    might be better than dealing with encoded strings.

    2. You might want to transmit integers as strings rather than use the
    XML-RPC integer type (which is limited to numbers between -2147483648
    and 2147483647).

    Cheers,
    Brian

    Comment

    • looping

      #3
      Re: XMLRPCServer issues


      Brian Quinlan wrote:[color=blue]
      > 1. Is there on option to get cx_Oracle to return string data as unicode
      > rather than strings objects? XML-RPC aside, dealing with unicode objects
      > might be better than dealing with encoded strings.[/color]

      I don't think cx_Oracle can return unicode string, so my code to
      convert string is not so bad.
      [color=blue]
      > 2. You might want to transmit integers as strings rather than use the
      > XML-RPC integer type (which is limited to numbers between -2147483648
      > and 2147483647).[/color]

      Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
      of the python xmlrpclib ?

      Thanks for your answer.

      Comment

      • Fredrik Lundh

        #4
        Re: XMLRPCServer issues

        "looping" wrote:
        [color=blue][color=green]
        > > 2. You might want to transmit integers as strings rather than use the
        > > XML-RPC integer type (which is limited to numbers between -2147483648
        > > and 2147483647).[/color]
        >
        > Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
        > of the python xmlrpclib ?[/color]

        the specification defines an integer field as a "four-byte signed integer".

        </F>



        Comment

        • looping

          #5
          Re: XMLRPCServer issues


          Fredrik Lundh wrote:[color=blue]
          > "looping" wrote:
          >[color=green][color=darkred]
          > > > 2. You might want to transmit integers as strings rather than use the
          > > > XML-RPC integer type (which is limited to numbers between -2147483648
          > > > and 2147483647).[/color]
          > >
          > > Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
          > > of the python xmlrpclib ?[/color]
          >
          > the specification defines an integer field as a "four-byte signed integer".
          >
          > </F>[/color]

          OK, I will remove my MAXINT hack and convert value to string.

          Thanks everybody for your fast answers, nice group with nice (and
          brillant) people.
          See you later for my next question.

          Comment

          Working...