Requests, 真正的为人类着想

2015-01-26 21:45:21 +08:00
 jacklong

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

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

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

5576 次点击
所在节点    Python
20 条回复
a2z
2015-01-26 22:02:58 +08:00
一直在用…
fredchen
2015-01-26 22:54:09 +08:00
爬虫利器
fy
2015-01-26 23:31:16 +08:00
欢迎回到火星基地,致远星风光可好?
ehs2013
2015-01-27 00:59:58 +08:00
Python 的 REST 库不用 requests 还能用什么……
ryd994
2015-01-27 02:01:31 +08:00
urllib3也相当好用,对大多数需要足够了
est
2015-01-27 08:52:53 +08:00
Ruby的 Net::HTTP 才是真渣。RestClient也是渣。
cdlxkill
2015-01-27 09:05:33 +08:00
正好需要,mark一记
Delbert
2015-01-27 09:14:02 +08:00
requests没法urlencode和decode啊
yueyoum
2015-01-27 10:25:14 +08:00
@Delbert

为何不能?
举个例子?
Delbert
2015-01-27 11:46:47 +08:00
对python2,urllib.quote()和urllib.unquote()
对python3,urllib.parse.quote()和urllin.parse.unquote()

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

请问requests应该怎么实现?我反正没找到。
9hills
2015-01-27 12:20:07 +08:00
@Delbert requests 本质上不用去做quote。。用params你随便写即可,内带了quote
Delbert
2015-01-27 12:41:49 +08:00
@9hills 不是参数,我要urldecode,但是requests没有。我保存的结果全是乱码。
Delbert
2015-01-27 12:42:37 +08:00
@yueyoum 见你楼下。回复的时候忘记提醒了。
yakczh
2015-01-27 13:40:36 +08:00
请求gbk页面返回
UnicodeEncodeError: 'gbk' codec can't encode character '\ufeff' in position 0: illegal multibyte sequence
recall704
2015-01-27 14:17:51 +08:00
我有个程序,开始用的,后来去掉了。
tidewind
2015-01-27 16:20:52 +08:00
#!/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
2015-01-27 21:49:01 +08:00
准备学习使用了,目前还是在urllib2中
lujiajing1126
2015-01-27 23:13:06 +08:00
httpie就是基于requests的~赞
GeekGao
2015-01-28 11:24:26 +08:00
去邮件列表里吐槽吧,让它变成standard library
rikeinei
2015-01-29 13:20:34 +08:00
这个确实不错

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/165664

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX