我的代码在Raspberry Pi 4系统(Raspbian)上运行良好,但是即使我使用的是字符串,也会在Petalinux系统中引发此奇怪的错误。该路径存在,我以root用户身份登录。
代码
import os
from pathlib import Path
...
video_filename = str((sorted(Path('/root/web_gui/Recordings').iterdir(), key=os.path.getctime))[-1])
错误
[2020-06-03 21:01:55,591] ERROR in app: Exception on /api/loadRecordings [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "Backend/filetest.py", line 94, in loadRecordings
paths = sorted(Path('/root/web_gui/Recordings').iterdir(), key=os.path.getctime)
File "/usr/lib/python3.5/genericpath.py", line 65, in getctime
return os.stat(filename).st_ctime
TypeError: argument should be string, bytes or integer, not PosixPath
PS:我已经尝试过'// root // web_gui // Recordings',但出现相同的错误
这似乎与文件中的其他代码有关。我已经复制了您的代码,它似乎对我有用。 (我已经用...
替换了一些路径)
>>> str((sorted(Path('/Users/.../Desktop').iterdir(), key=os.path.getctime))[-1])
'/Users/.../Desktop/Programming'