TypeError

John Machin sjmachin at lexicon.net
Thu Jan 7 02:31:16 CET 2010


On Jan 7, 11:14 am, John Machin <sjmac... at lexicon.net> wrote:
> On Jan 7, 3:29 am, MRAB <pyt... at mrabarnett.plus.com> wrote:
>
> > Victor Subervi wrote:
> > > ValueError: unsupported format character '(' (0x28) at index 54
> > >       args = ("unsupported format character '(' (0x28) at index 54",)
>
> > > Apparently that character is a "file separator", which I presume is an
> > > invisible character. I tried retyping the area in question, but with no
> > > avail (threw same error). Please advise. Complete code follows.
>
> OP is barking up the wrong tree. "file separator" has ordinal 28
> DECIMAL. Correct tree contains '(' (left parenthesis, ordinal 0x28
> (HEX)) as the error message says.

It took a bit of mucking about to get an example of that error message
(without reading the Python source code):

|>>> anything = object()

\|>>> "foo%(" % anything
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: format requires a mapping

|>>> "foo%(" % {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: incomplete format key

|>>> "foo%2(" % anything
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character '(' (0x28) at index 5

FWIW, the OP's message subject is "TypeError" but the reported message
contains ValueError ... possibly indicative of code that first builds
a format string (incorrectly) and then uses it with error messages
that can vary from run to run depending on exactly what was stuffed
into the format string.

I note that in the code shown there are examples of building an SQL
query where the table name is concocted at runtime via the %
operator ... key phrases: "bad database design" (one table per
store!), "SQL injection attack"

A proper traceback would be very nice ... at this stage it's not
certain what was the line of source that triggers the exception.



More information about the Python-list mailing list