繁体   English   中英

Flask系统找不到指定的路径:“ 130.127.5.9”

[英]Flask The system cannot find the path specified: '130.127.5.9'

我刚刚开始试验flask,并且尝试列出使用它的网络驱动程序。 这是我在浏览器中键入的命令。 但是我收到一个错误,它找不到路径http://127.0.0.1:5000/130.13.5.8/D/dir/

该功能适用​​于本地驱动程序

我知道为什么会失败。 在实际ip之前需要2'\\'或4'\\\\'。 但是当我尝试http://127.0.0.1:5000/////130.13.5.8/D/dir/时,它不起作用。 我什至尝试了%F%F,但似乎也没有成功。

@app.route('/<path:filepath>/dir/')
def get_dir(filepath):
    dir_listing = ''
    for entry in os.listdir(filepath):
        entry_type = 'dir' if os.path.isdir(os.path.join(filepath, entry)) else 'file'
        dir_listing += '{entry_name}|{entry_type}|'.format(entry_name=entry, entry_type=entry_type)
    return dir_listing

对于有相同问题的任何人,我的解决方法如下

   from ipaddress import ip_address
    try:
        ip_address(filepath.split('/')[0])
        filepath = '\\\\{filepath}'.format(filepath=filepath)
    except ValueError as e:
        pass

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM