Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1125 (closed defect: duplicate)

Opened 13 years ago

Last modified 12 years ago

500 error with Safari and serveFile

Reported by: Naomi Owned by: anonymous
Priority: normal Milestone: 1.0b2
Component: TurboGears Version: 1.0b1
Severity: major Keywords:


We've discovered what appears to be a bug in TurboGears that makes it so we are unable to serve files over a certain size to Safari users. This will affect anyone who is using cherrypy serveFile on the server and a Safari client. The user will see a 500 error, and the download won't work.

We are using cherrypy.lib.cptools.serveFile to allow users to download vcard and csv files. If the file being served is larger than a certain size, serveFile returns a Generator rather than a string. The problem occurs in the TurboGears controllers.py, in _process_output. When TurboGears attempts to fix a Safari XML HttpRequest encoding problem, the following code causes a 500 error:

if ua.browser == "safari":
    if isinstance(output, str):
        output = output.decode(enc)
    output = unicodechars.sub(lambda m: "&#x%x;" % ord(m.group(1)), output).encode("ascii")

unicodechars.sub does not support a Generator as the second argument. Since the output variable is a Generator, the execution of this last line gives us: "TypeError: expected string or buffer"

This could be a problem for anyone who is serving files to Safari users. They will be hit with an ugly 500 error.

As a temporary workaround, we changed the first line of the above code to:

if ua.browser == "safari" and not isinstance(output,types.GeneratorType)

Change History

comment:1 Changed 13 years ago by elvelind

does the fix in #1090 fix this too?

comment:2 Changed 13 years ago by Naomi

Yes it does - thanks!

comment:3 Changed 13 years ago by jorge.vargas

  • Status changed from new to closed
  • Resolution set to duplicate

this the same as #1090

now the question is do we want to apply #1090 seems like a hack to me

comment:4 Changed 13 years ago by elvelind

Sure it's a hack, but so is the orginal code, It's hard to make it not look as a hack. I say we commit it.

Note: See TracTickets for help on using tickets.