Hi,

I got a little problem when I my server goes wrong, the WebError did
catch the error and try to dump information about the exception and
send an email to me.  Unfortunately,  there is non-ascii character in
my TurboGears2 application.

    @expose()
    def split(self, email, input):
        """Perform split words task

        """
        # we failed here!
        runTask(input, email)
        # this line messes WebError up!
        flash(u'任務執行中 ... 完成後結果將會寄至 %s' % email)
        redirect('/')

As you see, there is a tradition chinese unicode in my program, just
below the operation that raises exception.  As the WebError dumps the
traceback, I think it doesn't except there are non-ascii characters in
code.  Then the mail sending failed.  Here is the trace I see from
console:

CGI Variables
-------------
  CONTENT_LENGTH: '-1'
  CONTENT_TYPE: 'application/x-www-form-urlencoded'
  HTTP_ACCEPT: 'application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
  HTTP_ACCEPT_CHARSET: 'Big5,utf-8;q=0.7,*;q=0.3'
  HTTP_ACCEPT_ENCODING: 'gzip,deflate,sdch'
  HTTP_ACCEPT_LANGUAGE: 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4'
  HTTP_CACHE_CONTROL: 'max-age=0'
  HTTP_CONNECTION: 'keep-alive'
  HTTP_COOKIE:
'domaintools=3cb6477b10f1c8566dc1abb87d068e40dce231ef287f32f5385edbac27fdf8b9d5f5ff7d'
  HTTP_HOST: '127.0.0.1:5050'
  HTTP_ORIGIN: 'https://127.0.0.1:5050'
  HTTP_REFERER: 'https://127.0.0.1:5050/split/form'
  HTTP_USER_AGENT: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5'
  PATH_INFO: '/split/split'
  REMOTE_ADDR: '127.0.0.1'
  REQUEST_METHOD: 'POST'
  SERVER_NAME: '0.0.0.0'
  SERVER_PORT: '8080'
  SERVER_PROTOCOL: 'HTTP/1.1'


WSGI Variables
--------------
  application: <function wrapper at 0x9adf844>
  beaker.cache: <beaker.cache.CacheManager object at 0x9ab5a4c>
  beaker.get_session: <bound method SessionMiddleware._get_session of
<beaker.middleware.SessionMiddleware object at 0x9ab59ec>>
  beaker.session: {'_accessed_time': 1266394064.0885379}
  paste.cookies: (<SimpleCookie:
domaintools='3cb6477b10f1c8566dc1abb87d068e40dce231ef287f32f5385edbac27fdf8b9d5f5ff7d'>,
'domaintools=3cb6477b10f1c8566dc1abb87d068e40dce231ef287f32f5385edbac27fdf8b9d5f5ff7d')
  paste.httpserver.thread_pool: <paste.httpserver.ThreadPool object at
0xb7ccd30c>
  paste.registry: <paste.registry.Registry object at 0x9ae576c>
  paste.throw_errors: True
  pylons.action_method: <bound method
RootController.routes_placeholder of
<domaintools.controllers.root.RootController object at 0x9ae7f0c>>
  pylons.controller: <domaintools.controllers.root.RootController
object at 0x9ae7f0c>
  pylons.environ_config: {'session': 'beaker.session', 'cache':
'beaker.cache'}
  pylons.pylons: <pylons.util.PylonsContext object at 0x9ae7eac>
  pylons.routes_dict: {'url': u'split/split', 'action':
u'routes_placeholder', 'controller': u'root'}
  repoze.tm.active: True
  repoze.who.logger: <logging.Logger instance at 0xb7cfee2c>
  repoze.who.plugins: {'form': <FriendlyFormPlugin 162372492>,
'main_identifier': <FriendlyFormPlugin 162372492>, 'authorization_md':
<repoze.what.middleware.AuthorizationMetadata object at 0x9ad9dec>,
'cookie': <AuthTktCookiePlugin 162372428>, 'sqlauth':
<repoze.who.plugins.sa.SQLAlchemyAuthenticatorPlugin object at
0x9ad9b0c>, 'sql_user_md':
<repoze.who.plugins.sa.SQLAlchemyUserMDPlugin object at 0x9ad9dac>}
  routes.route: <routes.route.Route object at 0x9a5c50c>
  routes.url: <routes.util.URLGenerator object at 0x9ae7e6c>
  toscawidgets.framework: <tw.mods.base.HostFramework object at
0x9ab5a6c>
  toscawidgets.javascript.require_once: False
  toscawidgets.prefix: '/toscawidgets'
  webflash.payload: '%7B%22status%22%3A%20%22error%22%2C%20%22message
%22%3A%20%22Sending%20task%20failed%20with%20exception%3A%20%28111%2C
%20%27Connection%20refused%27%29%22%7D'
  webob._parsed_post_vars: (MultiDict([('email', 'xxxxx'), ('input',
'smartlipowilton      \r\nmissbusypants\r\nmedtourguide \r
\nmamasofthelowcountry \r\nhshwindowcoverings     \r\nhansenip \r
\ngwenbridgewater   \r\nforallyourgiftsandmore  \r\ndabestblowjob\r
\ndabple    \r\ndj-james  \r\nstlouisfamilylawandmediation       \r
\nsharptechshears      \r\npersonalsblog \r\nfour-oceans    \r
\ntolantravel      \r\ngreenecountyflorist\r\ndoor-way\r\nflgc \r
\nsmythia   \r\noneworldlab   \r\nnasdaqsport    \r\nqbool      \r
\nhostalveraguas\r\nflashgamehell \r\nbanksgiftsandthings       \r\nh-
fch       \r\nparcakntr\r\ninsideoutspace\r\nadult-lifestyles       \r
\nnarnianews     \r\nmariocarrasco \r\nxn--2z1br4ko4ehtq \r\nmon-
auberge  \r\nbowenbalance\r\nhostodo  \r\nimpact4ever    \r
\n5starhotelreviews   \r\nemail2mobile  \r\ncarnevalepalmese   \r
\ngogogomez     \r\ntinkerblog       \r\nontariorefinance     \r
\nmcdonate       \r\ncquinn4444    \r\nbintzayed       \r\niekao
\r\ntolanto...t([('em...n')])>)
  webob._parsed_query_vars: (MultiDict([]), '')
  webob.adhoc_attrs: {'errors': 'ignore', 'language': 'en-us',
'start_response': <function repl_start_response at 0x9adfdbc>,
'response_type': None, 'response_ext': None, 'identity': None}
  wsgi process: 'Multithreaded'
  wsgiorg.routing_args: (<routes.util.URLGenerator object at
0x9ae7e6c>, {'url': u'split/split', 'action': u'routes_placeholder',
'controller': u'root'})
------------------------------------------------------------

            <p>Additionally an error occurred while sending the
&lt;weberror.reporter.EmailReporter object at 0x9c4aeac&gt; report:

            <pre>Traceback (most recent call last):
  File "/home/victor/tg2env/lib/python2.6/site-packages/
WebError-0.10.1-py2.6.egg/weberror/errormiddleware.py", line 450, in
send_report
    rep.report(exc_data)
  File "/home/victor/tg2env/lib/python2.6/site-packages/
WebError-0.10.1-py2.6.egg/weberror/reporter.py", line 54, in report
    self.to_addresses, msg.as_string())
  File "/usr/local/lib/python2.6/email/message.py", line 135, in
as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/local/lib/python2.6/email/generator.py", line 84, in
flatten
    self._write(msg)
  File "/usr/local/lib/python2.6/email/generator.py", line 109, in
_write
    self._dispatch(msg)
  File "/usr/local/lib/python2.6/email/generator.py", line 135, in
_dispatch
    meth(msg)
  File "/usr/local/lib/python2.6/email/generator.py", line 201, in
_handle_multipart
    g.flatten(part, unixfrom=False)
  File "/usr/local/lib/python2.6/email/generator.py", line 84, in
flatten
    self._write(msg)
  File "/usr/local/lib/python2.6/email/generator.py", line 109, in
_write
    self._dispatch(msg)
  File "/usr/local/lib/python2.6/email/generator.py", line 135, in
_dispatch
    meth(msg)
  File "/usr/local/lib/python2.6/email/generator.py", line 178, in
_handle_text
    self._fp.write(payload)
UnicodeEncodeError: 'ascii' codec can't encode characters in position
41124-41138: ordinal not in range(128)
</pre>

I can't find trac or google code for WebError, then I post here.  Hope
this could hep.

Regards.
Victor Lin.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to