推荐学习书目
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 · Nov 11, 2019 · 3388 views
    This topic created in 2401 days ago, the information mentioned may be changed or developed.

    我使用

    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 replies    2019-11-11 11:13:01 +08:00
    Fris
        1
    Fris  
       Nov 11, 2019   ❤️ 1
    不是长度的问题吧,是特殊字符 > 不能包含在文件名里
    xiri
        2
    xiri  
       Nov 11, 2019
    是特殊字符的原因吧
    ddvc
        3
    ddvc  
    OP
       Nov 11, 2019
    好的,谢谢
    ipwx
        4
    ipwx  
       Nov 11, 2019
    OSError 不是 Python 扔出来的,是操作系统扔出来的。
    XuanFei990
        5
    XuanFei990  
       Nov 11, 2019
    windows 下,文件或路径不能有以下 9 个特殊字符 < > | \ / : ? * "
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1595 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 16:26 · PVG 00:26 · LAX 09:26 · JFK 12:26
    ♥ Do have faith in what you're doing.