开发者

Python can't list my directory

I have this code in my Bottle app to list a directory full of files:

[Post(name[:-3]) for name in os.listdir("posts")]

On my local computer, it's fine. But on my server I am consistently getting this error:

OSError: [Errno 2] No such file or directory: 'posts'

os.listdir('.') and $ ls reports that the directory is there. os.getcwd() reports that I'm in the parent directory and should be able to access it. glob.glob("posts/*.md") returns nothing, so I don't think it's a problem with listdir. Running python over ssh and trying the same code is successful (ie: I get a list of Post objects).

Is there something I've missed?

Edit

Thanks for all the advice. The source of the problem was WSGI misconfiguration. I've since re-mounted 开发者_C百科the application using the proper config arguments, and all is well.


The first thing that comes to mind is permissions -- make sure that your permissions are set so that the app has at least read access. listdir will still say that something exists, even if it can't read it.

Next thought is that looks like a relative path -- are you sure that the relative path is correct? I know that you've found the directory through listdir('.') (so it shouldn't matter), but what happens if you actually hard code the full path to the directory? (there are plenty of times where "it shouldn't matter" does)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜