pyamf.remoting.RemotingError: HTTP Error 500: INTERNAL SERVER ERROR

使用python的pyamf客户端连接服务器的时候,只报出这样的错误:

pyamf.remoting.RemotingError: HTTP Error 500: INTERNAL SERVER ERROR

如果只看这个错误,会一头雾水的。必须得让报错更明细一些。

想了想,有两个办法让错误定位,一个是更改pyamf源码,一个是更改django的源码,让django直接打印出来500错误信息。

这里用第二种想法实现了一下。


django处理500的源码:python2.7/site-packages/django/core/handlers/base.py

源码如下, 中间那段是我添加的,这样可以显示出来详细错误了:

  def handle_uncaught_exception(self, request, resolver, exc_info):
        """
        Processing for any otherwise uncaught exceptions (those that will
        generate HTTP 500 responses). Can be overridden by subclasses who want
        customised 500 handling.

        Be *very* careful when overriding this because the error could be
        caused by anything, so assuming something like the database is always
        available would be an error.
        """
        from django.conf import settings

        if settings.DEBUG_PROPAGATE_EXCEPTIONS:
            raise

        logger.error('Internal Server Error: %s', request.path,
            exc_info=exc_info,
            extra={
                'status_code': 500,
                'request': request
            }
        )
        #============= Code start ========== by chang
        print "---------- HTTP 500 Error Msg ---------- "
        print exc_info
        import traceback
        print traceback.format_exc()
        print "---------------------------------------- "
        #============= Code end =========


        if settings.DEBUG:
            from django.views import debug
            return debug.technical_500_response(request, *exc_info)

        # If Http500 handler is not installed, re-raise last exception
        if resolver.urlconf_module is None:
            raise exc_info[1], None, exc_info[2]
        # Return an HttpResponse that displays a friendly error message.
        callback, param_dict = resolver.resolve500()
        return callback(request, **param_dict)


这样,问题就解决了。但是在生产环境里,最好不要这么用。







你可能感兴趣的:(exception,server,python,django,callback,import)