strange behaviour of colon within string

Discussion in 'Python' started by khany, Oct 19, 2009.

  1. khany

    khany Guest

    hello all,

    i am relatively new to python and i am trying to convert a php app i
    have over to it using googleapps.

    anyway here is the problem. i poll ebay API which has in its XML "<?
    xml version="1.0" encoding="utf-8"?><findItemsAdvancedRequest
    xmlns="http://www.ebay.com/marketplace/search/v1/services"> .... "

    however it fails to create the string UNLESS i remove the colon :)) in
    the http section. i tried to substitute it with chr(58) but it errors
    the same without showing why. does anyone know what i am doing wrong?
    is this peculiar to googleapps?

    thanks
    khany, Oct 19, 2009
    #1
    1. Advertising

  2. khany wrote:

    > hello all,
    >
    > i am relatively new to python and i am trying to convert a php app i
    > have over to it using googleapps.
    >
    > anyway here is the problem. i poll ebay API which has in its XML "<?
    > xml version="1.0" encoding="utf-8"?><findItemsAdvancedRequest
    > xmlns="http://www.ebay.com/marketplace/search/v1/services"> .... "
    >
    > however it fails to create the string UNLESS i remove the colon :)) in
    > the http section. i tried to substitute it with chr(58) but it errors
    > the same without showing why. does anyone know what i am doing wrong?
    > is this peculiar to googleapps?


    Please show us code & actual stacktraces. Python can generate XML just fine,
    so it's pretty likely that you are doing something wrong.

    Diez
    Diez B. Roggisch, Oct 19, 2009
    #2
    1. Advertising

  3. On Mon, Oct 19, 2009 at 05:44 -0700, khany wrote:
    > i am relatively new to python and i am trying to convert a php app i
    > have over to it using googleapps.


    Welcome!

    > anyway here is the problem. i poll ebay API which has in its XML "<?
    > xml version="1.0" encoding="utf-8"?><findItemsAdvancedRequest
    > xmlns="http://www.ebay.com/marketplace/search/v1/services"> .... "


    > however it fails to create the string UNLESS i remove the colon :)) in
    > the http section. i tried to substitute it with chr(58) but it errors
    > the same without showing why. does anyone know what i am doing wrong?
    > is this peculiar to googleapps?


    Could you please elaborate on "fails to create the string", preferably
    in the form of a traceback. It might also help us if we knew what
    behaviour you expected or what do you mean by "i remove the colon" .

    Wolodja

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.10 (GNU/Linux)

    iQIcBAEBCAAGBQJK3GSfAAoJEIt/fTDK8U78tp8P/1M91PtyhYuJLlhzooCRHIbo
    zOpEikGcpYCYiIK/EpnCPMjfarccJ8i3VDjyDQHmw7VyugRNiC8QqWY6HyckzgsK
    MPFuKApaeWd4B3h9pP8+CsFzxmt2PtDHgel8IckGIP6qlhoueLe/9+n/6I9uHZPS
    mgzq+S1+j8eVg1yMEprECe4jeCS4DoEhBPig3ZbECu04JW1iDmud0AKiG86/p3rq
    qjHwpS8hnUS1L89KMresefGWJit0t7p1Bjcs+fMzNTLN2oLos9/ZN7KFltF4FNNM
    VPgWtmRG96idwjvaXDapTrVyGEWYMheRSqJMoQYrZAhhxBh5qp3kyIlnZH0nImkf
    o4+8mFkUsxzESBV7VMTSsD6x/DAGZAw2su7AGGZKKGTgNmmsOhouk/mBT8bciHWD
    9ksEUu5nhMhYQvNyCjzdIB20a5pIzFRCN0xJUKV9o344PTbPwnRui+lkm0S9OdYY
    zDoitsdtfZ8OGAQ/WIwOLlQupNIh9zmD1uhNdrMn4Ld5iv+doOtIRQhlmRU/g+jR
    wQipHffX/Flb5RrdW3q7prnv291FbatVU6LmqWPCNxXfnUz16vMz1iNN72BP+KaH
    rMZlhMyyGRyir5n5hhC/r/uU3o2oAzAumZxu0hiwRx7AZCEDB5p1Yn0MaleRHVRi
    WjEt8oahCqF0s4qAKGqV
    =drxq
    -----END PGP SIGNATURE-----
    Wolodja Wentland, Oct 19, 2009
    #3
  4. khany

    khany Guest

    On 19 Oct, 13:44, khany <> wrote:
    > hello all,
    >
    > i am relatively new to python and i am trying to convert a php app i
    > have over to it using googleapps.
    >
    > anyway here is the problem. i poll ebay API which has in its XML "<?
    > xml version="1.0" encoding="utf-8"?><findItemsAdvancedRequest
    > xmlns="http://www.ebay.com/marketplace/search/v1/services">  .... "
    >
    > however it fails to create the string UNLESS i remove the colon :)) in
    > the http section. i tried to substitute it with chr(58) but it errors
    > the same without showing why. does anyone know what i am doing wrong?
    > is this peculiar to googleapps?
    >
    > thanks


    OK

    first thanks for replying so soon (most other groups out there take
    days)

    here is the code

    ========
    xml = '<?xml version="1.0" encoding="utf-8"?> \
    <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/
    search/v1/services"> \
    <categoryId>%(category)i</categoryId> \
    <keywords>%(searchtext)s</keywords> \
    <paginationInput> \
    <pageNumber>%(page)i</pageNumber> \
    <entriesPerPage>10</entriesPerPage> \
    </paginationInput> \
    </findItemsAdvancedRequest>' % \
    {'category':9834, 'searchtext':"bmw", 'page':1}
    print xml
    ========

    if i run this, the page is blank (even the source) with no errors or
    anything. if i remove the colon from the string (after the http) it
    prints the string on the browser fine.

    HTH
    khany, Oct 19, 2009
    #4
  5. khany

    StarWing Guest

    On Oct 19, 9:15 pm, khany <> wrote:
    > On 19 Oct, 13:44, khany <> wrote:
    >
    > > hello all,

    >
    > > i am relatively new to python and i am trying to convert a php app i
    > > have over to it using googleapps.

    >
    > > anyway here is the problem. i poll ebay API which has in its XML "<?
    > > xml version="1.0" encoding="utf-8"?><findItemsAdvancedRequest
    > > xmlns="http://www.ebay.com/marketplace/search/v1/services">  .... "

    >
    > > however it fails to create the string UNLESS i remove the colon :)) in
    > > the http section. i tried to substitute it with chr(58) but it errors
    > > the same without showing why. does anyone know what i am doing wrong?
    > > is this peculiar to googleapps?

    >
    > > thanks

    >
    > OK
    >
    > first thanks for replying so soon (most other groups out there take
    > days)
    >
    > here is the code
    >
    > ========
    >   xml = '<?xml version="1.0" encoding="utf-8"?> \
    >     <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/
    > search/v1/services"> \
    >     <categoryId>%(category)i</categoryId> \
    >     <keywords>%(searchtext)s</keywords> \
    >     <paginationInput> \
    >       <pageNumber>%(page)i</pageNumber> \
    >       <entriesPerPage>10</entriesPerPage> \
    >     </paginationInput> \
    >     </findItemsAdvancedRequest>' % \
    >     {'category':9834, 'searchtext':"bmw", 'page':1}
    >   print xml
    > ========
    >
    > if i run this, the page is blank (even the source) with no errors or
    > anything. if i remove the colon from the string (after the http) it
    > prints the string on the browser fine.
    >
    > HTH


    you can use a tri-quote string or make sure all lines end with \:
    xml1 = """<?xml version="1.0" encoding="utf-8"?>
    <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/\
    search/v1/services">
    <categoryId>%(category)i</categoryId>
    <keywords>%(searchtext)s</keywords>
    <paginationInput>
    <pageNumber>%(page)i</pageNumber>
    <entriesPerPage>10</entriesPerPage>
    </paginationInput>
    </findItemsAdvancedRequest>""" % \
    {'category':9834, 'searchtext':"bmw", 'page':1}

    xml2 = '<?xml version="1.0" encoding="utf-8"?>\n\
    <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/\
    search/v1/services">\n\
    <categoryId>%(category)i</categoryId>\n\
    <keywords>%(searchtext)s</keywords>\n\
    <paginationInput>\n\
    <pageNumber>%(page)i</pageNumber>\n\
    <entriesPerPage>10</entriesPerPage>\n\
    </paginationInput>\n\
    </findItemsAdvancedRequest>' % \
    {'category':9834, 'searchtext':"bmw", 'page':1}

    print xml1
    print xml2
    StarWing, Oct 19, 2009
    #5
  6. khany

    khany Guest

    On 19 Oct, 14:44, StarWing <> wrote:
    > On Oct 19, 9:15 pm, khany <> wrote:
    >
    >
    >
    >
    >
    > > On 19 Oct, 13:44, khany <> wrote:

    >
    > > > hello all,

    >
    > > > i am relatively new to python and i am trying to convert a php app i
    > > > have over to it using googleapps.

    >
    > > > anyway here is the problem. i poll ebay API which has in its XML "<?
    > > > xml version="1.0" encoding="utf-8"?><findItemsAdvancedRequest
    > > > xmlns="http://www.ebay.com/marketplace/search/v1/services">  .... "

    >
    > > > however it fails to create the string UNLESS i remove the colon :)) in
    > > > the http section. i tried to substitute it with chr(58) but it errors
    > > > the same without showing why. does anyone know what i am doing wrong?
    > > > is this peculiar to googleapps?

    >
    > > > thanks

    >
    > > OK

    >
    > > first thanks for replying so soon (most other groups out there take
    > > days)

    >
    > > here is the code

    >
    > > ========
    > >   xml = '<?xml version="1.0" encoding="utf-8"?> \
    > >     <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/
    > > search/v1/services"> \
    > >     <categoryId>%(category)i</categoryId> \
    > >     <keywords>%(searchtext)s</keywords> \
    > >     <paginationInput> \
    > >       <pageNumber>%(page)i</pageNumber> \
    > >       <entriesPerPage>10</entriesPerPage> \
    > >     </paginationInput> \
    > >     </findItemsAdvancedRequest>' % \
    > >     {'category':9834, 'searchtext':"bmw", 'page':1}
    > >   print xml
    > > ========

    >
    > > if i run this, the page is blank (even the source) with no errors or
    > > anything. if i remove the colon from the string (after the http) it
    > > prints the string on the browser fine.

    >
    > > HTH

    >
    > you can use a tri-quote string or make sure all lines end with \:
    > xml1 = """<?xml version="1.0" encoding="utf-8"?>
    >     <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/\
    > search/v1/services">
    >     <categoryId>%(category)i</categoryId>
    >     <keywords>%(searchtext)s</keywords>
    >     <paginationInput>
    >       <pageNumber>%(page)i</pageNumber>
    >       <entriesPerPage>10</entriesPerPage>
    >     </paginationInput>
    >     </findItemsAdvancedRequest>""" % \
    >     {'category':9834, 'searchtext':"bmw", 'page':1}
    >
    > xml2 = '<?xml version="1.0" encoding="utf-8"?>\n\
    >     <findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/\
    > search/v1/services">\n\
    >     <categoryId>%(category)i</categoryId>\n\
    >     <keywords>%(searchtext)s</keywords>\n\
    >     <paginationInput>\n\
    >       <pageNumber>%(page)i</pageNumber>\n\
    >       <entriesPerPage>10</entriesPerPage>\n\
    >     </paginationInput>\n\
    >     </findItemsAdvancedRequest>' % \
    >     {'category':9834, 'searchtext':"bmw", 'page':1}
    >
    > print xml1
    > print xml2


    StarWing,

    The triple String works a treat thanks. Not sure what the colon issue
    was though. Now im getting Unsupported verb errors but thats an ebay
    API issue i can work with.

    Thanks to all for your help

    khany
    khany, Oct 19, 2009
    #6
  7. khany

    Dave Angel Guest

    khany wrote:
    > On 19 Oct, 14:44, StarWing <> wrote:
    >
    >> On Oct 19, 9:15 pm, khany <> wrote:
    >>
    >>
    >>
    >>
    >>
    >>
    >>> On 19 Oct, 13:44, khany <> wrote:
    >>>
    >>>> <snip>
    >>>>
    >>>> however it fails to create the string UNLESS i remove the colon :)) in
    >>>> the http section. i tried to substitute it with chr(58) but it errors
    >>>> the same without showing why. does anyone know what i am doing wrong?
    >>>> is this peculiar to googleapps?
    >>>>

    >> <snip>
    >>> )
    >>>
    >>> here is the code
    >>>
    >>> ======
    >>> xml = <?xml version="1.0" encoding="utf-8"?> \
    >>> <findItemsAdvancedRequest xmlns=ttp://www.ebay.com/marketplace/
    >>> search/v1/services"> \
    >>> <categoryId>%(category)i</categoryId> \
    >>> <keywords>%(searchtext)s</keywords> \
    >>> <paginationInput> \
    >>> <pageNumber>%(page)i</pageNumber> \
    >>> <entriesPerPage>10</entriesPerPage> \
    >>> </paginationInput> \
    >>> </findItemsAdvancedRequest>' % \
    >>> {'category':9834, 'searchtext':"bmw", 'page':1}
    >>> print xml
    >>> ======
    >>>
    >>> if i run this, the page is blank (even the source) with no errors or
    >>> anything. if i remove the colon from the string (after the http) it
    >>> prints the string on the browser fine.
    >>>
    >>> HTH
    >>>

    >> you can use a tri-quote string or make sure all lines end with \:
    >> <snip>
    >>

    > StarWing,
    >
    > The triple String works a treat thanks. Not sure what the colon issue
    > was though. Now im getting Unsupported verb errors but thats an ebay
    > API issue i can work with.
    >
    > Thanks to all for your help
    >
    > khany
    >
    >

    The original version worked fine in Python 2.6.2, once I combined the
    line that the email/listserver split for us. I also don't know what the
    colon issue was; I suspect some other change happened at the same time
    you changed the colon.

    I also recommend the triple quote, for a few reasons. It avoids the
    risk that you'll forget one of the trailing backquotes. It avoids the
    risk of having an extra space after the backquote (most editors don't
    show the spaces, I insist on visible whitespace). And it lets you make
    the resulting string readable in source form.

    However, for long strings, I strongly recommend you not combine the
    string assignment with the % formatting logic. So I'd use a couple of
    lines, something like:

    format_string = """This
    is
    my formatted
    string %(formatfield)
    with some indentation preserved"""
    xml = format_string % (.....)

    You should consider running the program locally, and redirect the output
    into a text file. Then you can examine exactly what's being produced.
    Sometimes the browser adds its own surprises. I don't know anything
    about the googleapps constraints.

    DaveA
    Dave Angel, Oct 19, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrel
    Replies:
    0
    Views:
    967
    Darrel
    Dec 28, 2004
  2. =?Utf-8?B?Z3JlZyBz?=
    Replies:
    1
    Views:
    326
    Chad Devine
    Jan 18, 2005
  3. Kevin Kirkeby

    Setting property with colon (:) in it

    Kevin Kirkeby, Oct 1, 2003, in forum: Java
    Replies:
    4
    Views:
    2,025
    Dale King
    Oct 3, 2003
  4. Niall Macpherson

    Strange behaviour due to missing semi colon

    Niall Macpherson, Dec 16, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    97
    Niall Macpherson
    Dec 16, 2005
  5. RedGrittyBrick
    Replies:
    8
    Views:
    131
Loading...

Share This Page