V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
gaolinjie
V2EX  ›  Python

上传头像到服务器,用 PIL 保存出错

  •  
  •   gaolinjie · 2013-01-20 18:35:52 +08:00 · 2880 次点击
    这是一个创建于 4121 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在本地运行的时候一切都好,但当我部署到server(Ubuntu 12.10)上时,每次上传头像保存都会发生下面的错误:

    ```
    Traceback (most recent call last):
    File "/usr/local/lib/python2.6/dist-packages/tornado/web.py", line 1042, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
    File "/usr/local/lib/python2.6/dist-packages/tornado/web.py", line 1809, in wrapper
    return method(self, *args, **kwargs)
    File "/srv/www/domain.com/handler/user.py", line 127, in post
    avatar_96x96.save("./static/avatar/b_%s.png" % avatar_name, "PNG")
    File "/usr/local/lib/python2.6/dist-packages/PIL/Image.py", line 1433, in save
    fp = __builtin__.open(fp, "wb")
    IOError: [Errno 2] No such file or directory: './static/avatar/b_861c16ed-ecf4-5f49-ac5b-7d1565adf2a8.png'
    ```

    我也上网找了好多资料,貌似也没有什么解决方法,请问有什么解决办法没,谢谢
    3 条回复    1970-01-01 08:00:00 +08:00
    CoX
        1
    CoX  
       2013-01-20 19:17:03 +08:00
    错误很明显呐 No such file or directory
    还是用绝对路径吧,目前存放的路径是 handler/static/avatar/
    yetone
        2
    yetone  
       2013-01-20 20:13:10 +08:00
    用绝对路径
    gaolinjie
        3
    gaolinjie  
    OP
       2013-01-20 21:15:41 +08:00
    @CoX
    @yetone 谢谢,解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2195 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:13 · PVG 10:13 · LAX 19:13 · JFK 22:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.