473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Having problems with strings in HTML

Hi,

I get a very odd error:
ValueError: unsupported format character 't' (0x74) at index 237

Here's my code:
HI_LITE_FILE_NAME = '/var/tmp/out.txt'

print '''
<a
href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?input=&max=2&values_off=n o&remove_bracket=no&show_line_nr=yes&show_link_out =yes&decimal_places=10&show_classification=yes&db= arabidopsis&selection=any%20term&mode=&mode_nos=&y ellow_blue=yes&local_file_name=%(OUT_FILE_NAME)s&s how_instructions=no&expt_link=NASCArrays&max_adjus t=2&view_size=large&highlight=%(HI_LITE_FILE_NAME) s">GraphicalOutput</a>
''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME':
HI_LITE_FILE_NAME}

I wonder if this has something to do with HTML's % character.

KT

Jun 26 '06 #1
12 1907
Kiana Toufighi wrote:
Hi,

I get a very odd error:
ValueError: unsupported format character 't' (0x74) at index 237

Here's my code:
HI_LITE_FILE_NAME = '/var/tmp/out.txt'

print '''
<a
href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?input=&max=2&values_off=n o&remove_bracket=no&show_line_nr=yes&show_link_out =yes&decimal_places=10&show_classification=yes&db= arabidopsis&selection=any%20term&mode=&mode_nos=&y ellow_blue=yes&local_file_name=%(OUT_FILE_NAME)s&s how_instructions=no&expt_link=NASCArrays&max_adjus t=2&view_size=large&highlight=%(HI_LITE_FILE_NAME) s">GraphicalOutput</a>

''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME':
HI_LITE_FILE_NAME}

I wonder if this has something to do with HTML's % character.

KT


Yes it does. Have a look at urllib.quote and unquote. These may help.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Jun 26 '06 #2
On 27/06/2006 7:51 AM, Kiana Toufighi wrote:
Hi,

I get a very odd error:
ValueError: unsupported format character 't' (0x74) at index 237

Here's my code:
HI_LITE_FILE_NAME = '/var/tmp/out.txt'

print '''
<a
href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?input=&max=2&values_off=n o&remove_bracket=no&show_line_nr=yes&show_link_out =yes&decimal_places=10&show_classification=yes&db= arabidopsis&selection=any%20term&mode=&mode_nos=&y ellow_blue=yes&local_file_name=%(OUT_FILE_NAME)s&s how_instructions=no&expt_link=NASCArrays&max_adjus t=2&view_size=large&highlight=%(HI_LITE_FILE_NAME) s">GraphicalOutput</a>

''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME':
HI_LITE_FILE_NAME}
That code produces:
NameError: name 'OUT_FILE_NAME' is not defined
When that is remedied, *then* one gets the ValueError.
*Please*, when asking a question, post exactly the code that you ran,
and include the full traceback, not just the last line.

I wonder if this has something to do with HTML's % character.


I'm not sure why you are wondering. The error message told you exactly
what the problem was and exactly where it was (offset 237) in your
format string. . Your format string (the first operand of the string %
operator) contains ...&selection=any%20term... and the %20t looks like a
formatting operation, but (like it said) 't' is not valid.

To overcome this you would need to escape any '%' that is actually part
of the URL by doubling it ...&selection=any%%20term...

This is nothing to do with HTML ... *any* stray '%' will give you grief:

|>> '1% of %s are difficult to understand' % 'error messages'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: int argument required
Have you read this:
http://docs.python.org/lib/typesseq-strings.html
?
It may help.

Cheers,
John
Jun 26 '06 #3
On 27/06/2006 7:51 AM, Kiana Toufighi wrote:
Hi,

I get a very odd error:
ValueError: unsupported format character 't' (0x74) at index 237

Here's my code:
HI_LITE_FILE_NAME = '/var/tmp/out.txt'

print '''
<a
href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?input=&max=2&values_off=n o&remove_bracket=no&show_line_nr=yes&show_link_out =yes&decimal_places=10&show_classification=yes&db= arabidopsis&selection=any%20term&mode=&mode_nos=&y ellow_blue=yes&local_file_name=%(OUT_FILE_NAME)s&s how_instructions=no&expt_link=NASCArrays&max_adjus t=2&view_size=large&highlight=%(HI_LITE_FILE_NAME) s">GraphicalOutput</a>

''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME':
HI_LITE_FILE_NAME}
That code produces:
NameError: name 'OUT_FILE_NAME' is not defined
When that is remedied, *then* one gets the ValueError.
*Please*, when asking a question, post exactly the code that you ran,
and include the full traceback, not just the last line.

I wonder if this has something to do with HTML's % character.


I'm not sure why you are wondering. The error message told you exactly
what the problem was and exactly where it was (offset 237) in your
format string. . Your format string (the first operand of the string %
operator) contains ...&selection=any%20term... and the %20t looks like a
formatting operation, but (like it said) 't' is not valid.

To overcome this you would need to escape any '%' that is actually part
of the URL by doubling it ...&selection=any%%20term...

This is nothing to do with HTML ... *any* stray '%' will give you grief:

|>> '1% of %s are difficult to understand' % 'error messages'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: int argument required
Have you read this:
http://docs.python.org/lib/typesseq-strings.html
?
It may help.

Cheers,
John
Jun 26 '06 #4
In article <ma***************************************@python. org>,
Kiana Toufighi <ki************@utoronto.ca> wrote:
print '''
<a
href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?inp
ut=&max=2&values_off=no&remove_bracket=no&show_li ne_nr=yes&show_link_out=yes&de
cimal_places=10&show_classification=yes&db=arabid opsis&selection=any%20term&mod
e=&mode_nos=&yellow_blue=yes&local_file_name=%(OU T_FILE_NAME)s&show_instruction
s=no&expt_link=NASCArrays&max_adjust=2&view_size= large&highlight=%(HI_LITE_FILE
_NAME)s">GraphicalOutput</a>
''' % {'OUT_FILE_NAME': OUT_FILE_NAME, 'HI_LITE_FILE_NAME':
HI_LITE_FILE_NAME}


By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?
Jun 27 '06 #5
Lawrence D'Oliveiro <ld*@geek-central.gen.new_zealand> wrote:
Kiana Toufighi <ki************@utoronto.ca> wrote:
print '''
<a
href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?inp
ut=&max=2&values_off=no&remove_bracket=no&show_l ine_nr=yes&show_link_out=yes
[ ... ] ">GraphicalOutput</a>
''' [ ... ]


By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?


No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Jun 27 '06 #6
Sion Arrowsmith wrote:
By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?


No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.


Yes they should. CDATA sections can contain character entities; it's elements
that are ignored, not character/entity references.

</F>

Jun 27 '06 #7

"Sion Arrowsmith" <si***@chiark.greenend.org.uk> wrote in message
news:gL*******@news.chiark.greenend.org.uk...
By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?


No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.


It is CDATA but ampersands still need to be escaped.
Jun 27 '06 #8
Richard Brodie wrote:
"Sion Arrowsmith" <si***@chiark.greenend.org.uk> wrote in message
news:gL*******@news.chiark.greenend.org.uk...
By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?

No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.


It is CDATA but ampersands still need to be escaped.


Exactly. See
http://www.w3.org/TR/html4/appendix/...rsands-in-uris

Bye,
Walter Dörwald
Jun 27 '06 #9

[Kiana]
<a href="http://bbc.botany.utoronto.ca/[...]?input=&max=2[...]">
[Lawrence] By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?
[Sion] No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.


The W3C validator at http://validator.w3.org/ disagrees with you. It
accepts this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Test</title></head>
<body>
<p><a href="http://somewhere.com?a=1&amp;b=2">link</a></p>
</body></html>

but rejects this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Test</title></head>
<body>
<p><a href="http://somewhere.com?a=1&b=2">link</a></p>
</body></html>

saying "cannot generate system identifier for general entity "b" [...] The
most common cause of this error is unencoded ampersands in URLs".

--
Richie Hindle
ri****@entrian.com
Jun 27 '06 #10
Richard Brodie <R.******@rl.ac.uk> wrote:
"Sion Arrowsmith" <si***@chiark.greenend.org.uk> wrote in message
news:gL*******@news.chiark.greenend.org.uk...
[ ... ]
By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?

No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.

It is CDATA but ampersands still need to be escaped.


I'll take back that "shouldn't" as per Fredrik's post. Maybe they
*should* be escaped, but they don't *need* to be. I've never, and
never seen, anyone doing that in a decade of writing cgi; a straw poll
of peers suggests that the majority would write the former; and I've
never encountred a browser getting tripped up by it. I suppose you
might need it if you've got parameters called quot or nbsp, but it's
hardly the most broken way of writing HTML.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Jun 27 '06 #11
Sion Arrowsmith wrote:
I've never encountred a browser getting tripped up by it. I suppose you
might need it if you've got parameters called quot or nbsp


There are many more entities than you can comfortably remember, and
browsers can interpret anything starting with one as being an entity
reference, hence all the problems with parameters like 'section' (->
&sect;). Plus of course there's nothing stopping future browsers
supporting more entities, breaking your apps.

Just write &amp;. There's no reason not to (except ignorance). The fact
that so much of the web is written with broken HTML is not an argument
for doing the same.

--
And Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/

Jun 28 '06 #12
In article <e7**********@blackmamba.itd.rl.ac.uk>,
"Richard Brodie" <R.******@rl.ac.uk> wrote:
"Sion Arrowsmith" <si***@chiark.greenend.org.uk> wrote in message
news:gL*******@news.chiark.greenend.org.uk...
By the way, you _do_ realize that your "&" characters should be escaped
as "&amp;", don't you?


No they shouldn't. They part of the url, which is (IIRC) a CDATA
attribute of the A element, not PCDATA.


It is CDATA but ampersands still need to be escaped.


I believe it's common for CGI argument-parsing routines to accept ";" as
a synonym for "&" as the argument separator. Certainly the code I use
does.
Jun 29 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: josh dismukes | last post by:
//Query the Database $query = "SELECT type FROM map WHERE map_file = " . $_SESSION . " AND col = " . $_SESSION . " AND row = " . $_SESSION; $db_result = @mysql_query($query); $db_cell_type =...
8
by: Bart Plessers \(artabel\) | last post by:
Hello, I have problems with the quotation mark and strings in my asp script. I made a general FORM (myform.asp) to read out data from a dbase Some vars are defined in the FORM: SQL_DBASE...
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
1
by: Rolan | last post by:
Perhaps someone has experience these two problems and if there are any fixes or workarounds, I sure would like to know. I'm using Access 97. When exporting data in html from one database that...
12
by: LongBow | last post by:
Hello all, From doing a google serach in the newsgroups I found out that a string can't be returned from a function, but using a char* I should be able to do it. I have spent most of the day...
9
by: robbie.carlton | last post by:
Hello! I've programmed in c a bit, but nothing very complicated. I've just come back to it after a long sojourn in the lands of functional programming and am completely stumped on a very simple...
7
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
5
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have...
1
by: nass | last post by:
hello everyone.. i am not sure what is wrong - never liked strings anyway! my problem is that i am trying to save a QCstring in a shared memory segment and i get a segmentation fault.. here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.