Why does Python give "OSError: [Errno 36] File name too long" for filename shorter than filesystem's limit?

Why does Python give "OSError: [Errno 36] File name too long" for filename shorter than filesystem's limit?

以下代码产生意外异常:

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

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

那么,为什么 Python 在实际没有超过文件名长度限制时引发此异常?

我找到了解决办法。事实证明,我不是在处理纯 ext4——它实际上是在 ext4 之上分层的 ecryptfs,从以前的 Ubuntu 安装中继承而来。正如 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.

的未接受答案中所建议的那样