最近想用Python的psutil获取磁盘信息(disk_usage),但是获取时报了很奇怪的错误。
我的源代码:
#我的系统是Windows 11,psutil是5.9.5
import psutil
disk_partitions = psutil.disk_partitions()
for partition in disk_partitions:
disk_usage = psutil.disk_usage(partition.mountpoint)
print("磁盘容量和使用情况 - {}: {}".format(partition.device, disk_usage))
错误信息:
Traceback (most recent call last):
File "D:\Program Files\Python311\hhh.py", line 5, in <module>
disk_usage = psutil.disk_usage(partition.mountpoint)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\psutil\__init__.py", line 2005, in disk_usage
return _psplatform.disk_usage(path)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\psutil\_pswindows.py", line 280, in disk_usage
total, free = cext.disk_usage(path)
SystemError: argument 1 (impossible<bad format char>)
网上搜不到,谁能帮我解决一下,谢谢