strange behaviour of colon within string

K

khany

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
 
D

Diez B. Roggisch

khany said:
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
 
W

Wolodja Wentland

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-----
 
K

khany

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
 
S

StarWing

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
 
K

khany

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
 
D

Dave Angel

khany said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top