谢谢你的回复。
我上午下的版本,Eurasia-3.0.0a6-snapshot.tar.bz2, 是最新的了。
关于hello.py的内容,我是直接帖了guide(eurasiaguide-3.0.0a6-snapshot)里的代码。
hello.py文件:
#!/usr/bin/python2.5
#-*- coding: utf-8 -*-
import os.path
from eurasia import config, mainloop
def handler(httpfile):
filename = '/www' + httpfile.path_info
if not os.uri.exists(filename): # 文件不存在 , 返回 404 (未找到)
httpfile.status = 404
httpfile.write('<h1>Not Found</h1>')
return httpfile.close()
if os.path.isdir(filename): # 请求的是目录, 返回 403 (拒绝访问)
httpfile.status = 403
httpfile.write('<h1>Forbidden</h1>')
return httpfile.close()
try:
data = open(filename).read()
except (IOError, OSError): # 文件读取错误, 返回 500
httpfile.status = 500
httpfile.write('<h1>Internal Server Error</h1>')
return httpfile.close()
# 正确返回文件内容, 因为设定了 Content-Type 为 application/octet-stream,
# 浏览器将提示用户是否下载该文件, 而不是直接显示出来
httpfile['Content-Type'] = 'application/octet-stream'
httpfile.write(data)
httpfile.close()
config(handler=handler, port=8080)
mainloop()
访问了地址:
http://localhost:8080/ddd出错:
HoLin:tmp holin$ python hello.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/eurasia-3.0.0a6-py2.5.egg/eurasia/socket2.py", line 558, in mainloop0
stackless.run()
File "hello.py", line 9, in handler
if not os.uri.exists(filename): # 文件不存在 , 返回 404 (未找到)
AttributeError: 'module' object has no attribute 'uri'
我想可能是我系统配置的问题,可能python2.5没装好。 我再看看
--
Regards
HoLin