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

Requests, 真正的为人类着想

  •  
  •   jacklong ·
    jack-long · Jan 26, 2015 · 6888 views
    This topic created in 4323 days ago, the information mentioned may be changed or developed.

    Python 标准库中的 urllib2 模块提供了你所需要的大多数 HTTP 功能,但是它的 API 太渣了。它是为另一个时代、另一个互联网所创建的。它需要巨量的工作,甚至包括各种方法覆盖,来完成最简单的任务。

    在Python的世界里,事情不应该这么麻烦。

    From http://cn.python-requests.org/zh_CN/latest/

    20 replies  •  2015-01-29 13:20:34 +08:00
    a2z
    a2z
    Jan 26, 2015 via iPhone
    1
    一直在用…
    fredchen
    fredchen
    Jan 26, 2015
    2
    爬虫利器
    fy
    fy
    Jan 26, 2015❤️1
    3
    欢迎回到火星基地,致远星风光可好?
    ehs2013
    ehs2013
    Jan 27, 2015
    4
    Python 的 REST 库不用 requests 还能用什么……
    ryd994
    ryd994
    Jan 27, 2015
    5
    urllib3也相当好用,对大多数需要足够了
    est
    est
    Jan 27, 2015
    6
    Ruby的 Net::HTTP 才是真渣。RestClient也是渣。
    cdlxkill
    cdlxkill
    Jan 27, 2015 via iPhone
    7
    正好需要,mark一记
    Delbert
    Delbert
    Jan 27, 2015
    8
    requests没法urlencode和decode啊
    yueyoum
    yueyoum
    Jan 27, 2015
    9
    @Delbert

    为何不能?
    举个例子?
    Delbert
    Delbert
    Jan 27, 2015
    10
    对python2,urllib.quote()和urllib.unquote()
    对python3,urllib.parse.quote()和urllin.parse.unquote()

    urlencode就是将空格变为%20,将/变为%2F的东西。
    urldecode的作用相反。

    请问requests应该怎么实现?我反正没找到。
    9hills
    9hills
    Jan 27, 2015
    11
    @Delbert requests 本质上不用去做quote。。用params你随便写即可,内带了quote
    Delbert
    Delbert
    Jan 27, 2015
    12
    @9hills 不是参数,我要urldecode,但是requests没有。我保存的结果全是乱码。
    Delbert
    Delbert
    Jan 27, 2015
    13
    @yueyoum 见你楼下。回复的时候忘记提醒了。
    yakczh
    yakczh
    Jan 27, 2015
    14
    请求gbk页面返回
    UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte sequence
    recall704
    recall704
    Jan 27, 2015
    15
    我有个程序,开始用的,后来去掉了。
    tidewind
    tidewind
    Jan 27, 2015
    16
    #!/usr/bin/env python
    # -*- coding:utf-8 -*-

    import requests
    import urllib

    url = 'http://zh.wikipedia.org/wiki/'+"猪"

    print urllib.quote(url)
    print requests.utils.quote(url)
    rurl = requests.utils.quote(url)

    print urllib.unquote(rurl)
    print requests.utils.unquote(rurl)
    assassinpig
    assassinpig
    Jan 27, 2015
    17
    准备学习使用了,目前还是在urllib2中
    lujiajing1126
    lujiajing1126
    Jan 27, 2015
    18
    httpie就是基于requests的~赞
    R4rvZ6agNVWr56V0
    R4rvZ6agNVWr56V0
    Jan 28, 2015
    19
    去邮件列表里吐槽吧,让它变成standard library
    rikeinei
    rikeinei
    Jan 29, 2015
    20
    这个确实不错
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1936 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 12:15 · PVG 20:15 · LAX 04:15 · JFK 07:15
    ♥ Do have faith in what you're doing.