CGI和日志记录模块 [英] CGI and logging module

查看:88
本文介绍了CGI和日志记录模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:


Python 2.3.4(#2,2004年11月14日,18:06:48)

[GCC 2.95.4 20020320 [FreeBSD]]关于freebsd4


与Apache / 1.3.26。以下脚本导致内部服务器错误

(Apache错误日志AFAIK中没有任何内容):


#!/ usr / local / bin / python


导入日志


打印&内容类型:text / html\\\
\ n

print"< html>< head>< title>< / title>< / head>< body>< h1> OK< / h1>"""

print"< / body>< / html>"


注释掉import语句的相同脚本按预期工作。

有没有遇到过这个?我用google搜索没有成功。


谢谢


彼得

I am using:

Python 2.3.4 (#2, Nov 14 2004, 18:06:48)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4

with Apache/1.3.26. The following script causes an Internal Server Error
(with nothing in the Apache error logs AFAIK):

#!/usr/local/bin/python

import logging

print "Content-type: text/html\n\n"
print "<html><head><title></title></head><body><h1>OK</h1>"""
print "</body></html>"

The same script with the import statement commented out works as expected.
Has anyone encountered this? I have googled without success.

Thanks

Peter

推荐答案

Peter Mott写道:
Peter Mott wrote:
我正在使用:

Python 2.3.4(#2,2004年11月14日,18:06:48)
[ GCC 2.95.4 20020320 [FreeBSD]] on freebsd4

使用Apache / 1.3.26。以下脚本导致内部服务器错误
(Apache错误日志AFAIK中没有任何内容):

#!/ usr / local / bin / python

导入记录

打印"内容类型:text / html\\\
\ n"
打印"< html>< head>< title>< / title> < / head>< body>< h1> OK< / h1>"""
print"< / body>< / html>"
注释掉import语句的相同脚本按预期工作。
是否有人遇到此问题?我用google搜索没有成功。
I am using:

Python 2.3.4 (#2, Nov 14 2004, 18:06:48)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4

with Apache/1.3.26. The following script causes an Internal Server Error
(with nothing in the Apache error logs AFAIK):

#!/usr/local/bin/python

import logging

print "Content-type: text/html\n\n"
print "<html><head><title></title></head><body><h1>OK</h1>"""
print "</body></html>"

The same script with the import statement commented out works as expected.
Has anyone encountered this? I have googled without success.




无法解决具体问题,但有两点:


1。你应该回来\\\\ n,我相信,不仅仅是行间的
\ n。


2.如果你想要看看出了什么问题,在import语句周围试一试/除了
并尝试写一些有用的东西

以及你的结果:


err =''''

尝试:

导入日志

除了Exception,例如:

err = str(ex)


print''内容类型:test / html\r\\\
\r\\\
''

blah blah blah

print''< p>错误:%s< / p> \\ n \\ n'


如果可以的话设法导入sys和traceback模块,

你可以使用

''''获得一个更完全格式化的异常.join(traceback.format_exception(* sys.exc_info( )))


-Peter



Can''t help on the specific problem, but two points:

1. You are supposed to be returning \r\n, I believe, not just
\n between lines.

2. If you want to see what is going wrong, put a try/except
around the import statement and try to write something useful
along with your results:

err = ''''
try:
import logging
except Exception, ex:
err = str(ex)

print ''Content-type: test/html\r\n\r\n''
blah blah blah
print ''<p>Error: %s</p>\r\n''

If you can manage to import the sys and traceback modules,
you can get a more fully formatted exception using
''''.join(traceback.format_exception(*sys.exc_info() ))

-Peter


Peter Hansen写道:
Peter Hansen wrote:
2.如果你想看看出了什么问题,请在导入周围试一试/除了
声明并尝试写一些有用的东西
以及你的结果:

错误=''''
尝试:
导入日志
除了Exception,ex :
err = str(ex)

print''内容类型:test / html\r\\\
\r\ n''
等等等等等等等等
打印''< p>错误:%s< / p> \\ n \\ n'

如果您可以设法导入sys和traceback模块,你可以使用
''''获得一个更完全格式化的异常.join(traceback.format_exception(* sys.exc_info()))
2. If you want to see what is going wrong, put a try/except
around the import statement and try to write something useful
along with your results:

err = ''''
try:
import logging
except Exception, ex:
err = str(ex)

print ''Content-type: test/html\r\n\r\n''
blah blah blah
print ''<p>Error: %s</p>\r\n''

If you can manage to import the sys and traceback modules,
you can get a more fully formatted exception using
''''.join(traceback.format_exception(*sys.exc_info() ))




我''刚刚发现了cgitb模块,它提供了一种最小的侵入式方法来调试cgi脚本 - 只需添加


import cgitb

cgitb.enable()


位于脚本顶部。


(又一个)

彼得



I''ve just discovered the cgitb module, which offers a minimally intrusive
way to debug cgi scripts - just add

import cgitb
cgitb.enable()

at the top of the script.

(Yet another)
Peter


彼得,

有您考虑过使用mod_python作为CGI的替代方案吗?它提供了许多好处,包括部分会话支持,集成到Apache的内部和缓存字节码中。如果您愿意,我可以为您提供一些

示例代码(虽然在线文档非常好)


问候,

Andrew


On Thu,2004-11-18 at 22:37 +0100,Peter Otten写道:
Peter,
Have you considered using mod_python as an alternative to CGI? It offers
a number of benefits including partial session support, integration into
Apache''s internals and caching bytecode. I can provide you with some
sample code if you wish (although the online documentation is very good)

Regards,
Andrew

On Thu, 2004-11-18 at 22:37 +0100, Peter Otten wrote:
Peter Hansen写道:
Peter Hansen wrote:
2.如果你想看看出了什么问题,可以在import语句周围试一下/尝试写一些有用的东西
以及你的结果:

错误=''''
尝试:
导入日志
除了异常,例如:
err = str(ex)

打印''内容类型:test / html \\\\\\\'
blah blah blah
print''< p>错误:%s< / p> \\ \\ r \\ n''

如果你可以设法导入sys和traceback模块,
你可以使用
''''获得更完全格式化的异常.join (traceback.format_exception(* sys.exc_info()))
2. If you want to see what is going wrong, put a try/except
around the import statement and try to write something useful
along with your results:

err = ''''
try:
import logging
except Exception, ex:
err = str(ex)

print ''Content-type: test/html\r\n\r\n''
blah blah blah
print ''<p>Error: %s</p>\r\n''

If you can manage to import the sys and traceback modules,
you can get a more fully formatted exception using
''''.join(traceback.format_exception(*sys.exc_info() ))



我有刚刚发现了cgitb模块,它提供了一种最小的侵入性方式来调试cgi脚本 - 只需添加

import cgitb
cgitb.enable()

在剧本的顶部。

(又一个)
彼得



I''ve just discovered the cgitb module, which offers a minimally intrusive
way to debug cgi scripts - just add

import cgitb
cgitb.enable()

at the top of the script.

(Yet another)
Peter



-

Andrew James< dr**@gremlinhosting.com>


--
Andrew James <dr**@gremlinhosting.com>


这篇关于CGI和日志记录模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆