为什么Python给“OSError:[Errno 36]文件名太长”对于文件名比文件系统的限制更短? [英] Why does Python give "OSError: [Errno 36] File name too long" for filename shorter than filesystem's limit?

查看:3537
本文介绍了为什么Python给“OSError:[Errno 36]文件名太长”对于文件名比文件系统的限制更短?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码产生一个意想不到的异常:

  open(52bbe674cdc81d4140099b84fa69eea4249bcceee75bcbe4838d911ab076547cfdad3c1c5197752a98e5525fe76613dbe52dcdb1a9a397669babce0f101d010142cffa000000.csv,w)
OSERROR:[错误36]文件名太长: '52bbe674cdc81d4140099b84fa69eea4249bcceee75bcbe4838d911ab076547cfdad3c1c5197752a98e5525fe76613dbe52dcdb1a9a397669babce0f101d010142cffa000000.csv'

这是出乎意料的,因为我的文件系统是ext4(根据维基百科)有一个255字节的文件名长度限制。上面的文件名长度为144.



那么为什么Python在文件名长度限制还没有被超过的时候引发这个异常呢?

解决方案

我找到了一个解决方案。事实证明,我没有处理纯粹的ext4 ---实际上ecryptfs分层在ext4之上,从以前的Ubuntu安装结转。正如对这个相关问题< a> ecryptfs层将文件名长度限制为143个字符。在ecryptfs下的文件名长度限制的明确答案可以找到这里


The following code yields an unexpected exception:

open("52bbe674cdc81d4140099b84fa69eea4249bcceee75bcbe4838d911ab076547cfdad3c1c5197752a98e5525fe76613dbe52dcdb1a9a397669babce0f101d010142cffa000000.csv", "w")
OSError: [Errno 36] File name too long: '52bbe674cdc81d4140099b84fa69eea4249bcceee75bcbe4838d911ab076547cfdad3c1c5197752a98e5525fe76613dbe52dcdb1a9a397669babce0f101d010142cffa000000.csv'

This is unexpected because my filesystem is ext4 which (according to Wikipedia) has a 255 byte filename length limit. The above filename has a length of 144.

So why does Python raise this exception when the filename length limit hasn't actually been exceeded?

解决方案

I've found a solution. It turns out that I'm not dealing with pure ext4---it's actually ecryptfs layered atop ext4, carried over from a previous Ubuntu install. As suggested in an unaccepted answer to this related question the ecryptfs layer imposes a limit of 143 characters to the filename length. A definitive answer to the file name length limit under ecryptfs can be found here.

这篇关于为什么Python给“OSError:[Errno 36]文件名太长”对于文件名比文件系统的限制更短?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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