V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ddvc
V2EX  ›  Python

怎么去除 Python 下载文件时的文件名长度 50 限制

  •  
  •   ddvc · 2019-11-11 10:31:25 +08:00 · 2788 次点击
    这是一个创建于 1599 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用

    urllib.request.urlretrieve(fileLink,fileNmae)

    进行批量文件下载时报错

    正在下载:agentx1_1.1.0-8bb70d4416f9574086b2ca67728074115..>

    Traceback (most recent call last):

    File "*\down.py", line 48, in <module></module>

    urllib.request.urlretrieve(fileLink,fileNmae)
    

    File "*\Python\lib\urllib\request.py", line 257, in urlretrieve

    tfp = open(filename, 'wb')
    

    OSError: [Errno 22] Invalid argument: 'agentx1_1.1.0-8bb70d4416f9574086b2ca67728074115..>'

    尝试

    urllib.request.urlretrieve(fileLink,fileNmae[0:49])

    强制截取文件名长度,发现低于 50 的长度可以正常下载,超过 50 则不行

    请有办法解除这个限制吗

    5 条回复    2019-11-11 11:13:01 +08:00
    Fris
        1
    Fris  
       2019-11-11 10:36:50 +08:00   ❤️ 1
    不是长度的问题吧,是特殊字符 > 不能包含在文件名里
    xiri
        2
    xiri  
       2019-11-11 10:41:14 +08:00
    是特殊字符的原因吧
    ddvc
        3
    ddvc  
    OP
       2019-11-11 10:42:09 +08:00
    好的,谢谢
    ipwx
        4
    ipwx  
       2019-11-11 11:06:29 +08:00
    OSError 不是 Python 扔出来的,是操作系统扔出来的。
    XuanFei990
        5
    XuanFei990  
       2019-11-11 11:13:01 +08:00
    windows 下,文件或路径不能有以下 9 个特殊字符 < > | \ / : ? * "
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1676 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:00 · PVG 08:00 · LAX 17:00 · JFK 20:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.