Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > strange behaviour of colon within string

Reply
Thread Tools

strange behaviour of colon within string

 
 
khany
Guest
Posts: n/a
 
      10-19-2009
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(5 but it errors
the same without showing why. does anyone know what i am doing wrong?
is this peculiar to googleapps?

thanks
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      10-19-2009
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(5 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
 
Reply With Quote
 
 
 
 
Wolodja Wentland
Guest
Posts: n/a
 
      10-19-2009
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(5 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+CsFzxmt2PtDHgel8IckGIP6qlhoueL e/9+n/6I9uHZPS
mgzq+S1+j8eVg1yMEprECe4jeCS4DoEhBPig3ZbECu04JW1iDm ud0AKiG86/p3rq
qjHwpS8hnUS1L89KMresefGWJit0t7p1Bjcs+fMzNTLN2oLos9/ZN7KFltF4FNNM
VPgWtmRG96idwjvaXDapTrVyGEWYMheRSqJMoQYrZAhhxBh5qp 3kyIlnZH0nImkf
o4+8mFkUsxzESBV7VMTSsD6x/DAGZAw2su7AGGZKKGTgNmmsOhouk/mBT8bciHWD
9ksEUu5nhMhYQvNyCjzdIB20a5pIzFRCN0xJUKV9o344PTbPwn Rui+lkm0S9OdYY
zDoitsdtfZ8OGAQ/WIwOLlQupNIh9zmD1uhNdrMn4Ld5iv+doOtIRQhlmRU/g+jR
wQipHffX/Flb5RrdW3q7prnv291FbatVU6LmqWPCNxXfnUz16vMz1iNN72B P+KaH
rMZlhMyyGRyir5n5hhC/r/uU3o2oAzAumZxu0hiwRx7AZCEDB5p1Yn0MaleRHVRi
WjEt8oahCqF0s4qAKGqV
=drxq
-----END PGP SIGNATURE-----

 
Reply With Quote
 
khany
Guest
Posts: n/a
 
      10-19-2009
On 19 Oct, 13:44, khany <(E-Mail Removed)> 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(5 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
 
Reply With Quote
 
StarWing
Guest
Posts: n/a
 
      10-19-2009
On Oct 19, 9:15*pm, khany <(E-Mail Removed)> wrote:
> On 19 Oct, 13:44, khany <(E-Mail Removed)> 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(5 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

 
Reply With Quote
 
khany
Guest
Posts: n/a
 
      10-19-2009
On 19 Oct, 14:44, StarWing <(E-Mail Removed)> wrote:
> On Oct 19, 9:15*pm, khany <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On 19 Oct, 13:44, khany <(E-Mail Removed)> 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(5 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
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      10-19-2009
khany wrote:
> On 19 Oct, 14:44, StarWing <(E-Mail Removed)> wrote:
>
>> On Oct 19, 9:15 pm, khany <(E-Mail Removed)> wrote:
>>
>>
>>
>>
>>
>>
>>> On 19 Oct, 13:44, khany <(E-Mail Removed)> 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(5 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange behaviour with string PaulR C++ 11 02-05-2011 07:14 PM
Perl 5.8 RE for fixed string with an optional colon terminated prefix RedGrittyBrick Perl Misc 8 04-08-2010 08:41 PM
Strange behaviour while string concatenation Rajpreet Perl Misc 1 02-12-2008 05:58 PM
Strange behaviour due to missing semi colon Niall Macpherson Perl Misc 3 12-16-2005 04:59 PM
regex: colon screwing up my pattern? Darrel ASP .Net 0 12-28-2004 12:56 PM



Advertisments