推荐学习书目
› 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
oldbird
V2EX  ›  Python

通过 BeautifulSoup 解析到的一个文件地址,通过 urllib 下载提示 ASCII 错误,请教

  •  
  •   oldbird · Oct 14, 2019 · 2794 views
    This topic created in 2538 days ago, the information mentioned may be changed or developed.

    用的 py3,从 uci 上自动下载需要的 whl 文件,通过 bs 解析得到的文件名,在 pycharm 里打印出来为 rasterio‑1.0.24+gdal24‑cp35‑cp35m‑win32.whl

    通过 urllib.request.urlretrieve 下载时报错,提示 UnicodeEncodeError: 'ascii' codec can't encode character '\u2011' in position 34: ordinal not in range(128)

    查了下这个\u2011 是文件名中的-, 尝试了一下新建 encoding='utf-8'的 txt 文件,写入该文件名字符串,可写入; 新建 encoding='cp936'的 txt 文件,写入文件名字符串会报错。

    不知道怎么解决了,请教

    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2577 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 15:25 · PVG 23:25 · LAX 08:25 · JFK 11:25
    ♥ Do have faith in what you're doing.