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
oldbird
V2EX  ›  Python

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

  •  
  •   oldbird · 2019-10-14 18:53:56 +08:00 · 2105 次点击
    这是一个创建于 1627 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用的 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 文件,写入文件名字符串会报错。

    不知道怎么解决了,请教

    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1048 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:35 · PVG 06:35 · LAX 15:35 · JFK 18:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.