我写的一个python package: urlfetch

31 views
Skip to first unread message

duyue

unread,
Apr 5, 2012, 7:21:18 AM4/5/12
to 北航开源软件俱乐部
hi, all

来宣传一下我写的urlfetch

urlfetch是一个python的http client库, 支持python3, 目标就是做到简单粗暴。

之前用urllib2非常罗嗦, 如果要做点什么cookie, 文件上传, multipart表单之类的话, 代码行数直接过百了。
pycurl呢, 一个个setopt也比较累, 而且当时的pycurl有bug, reset多了就会抛Deallocating None的异常(现在已经修复了)。
于是我写了urlfetch.

可以看看urlfetch的几个小例子, 非常简单, 用urllib2代码怎么也得三倍以上吧。
https://github.com/lyxint/urlfetch/tree/master/examples

类似的库:
有一个urllib3, 支持链接池。
还有一个requests, 基于urlib3的, 加上了ssl验证之类的。requests早期是基于pycurl的, 后来才换成了urllib3.
我把urlfetch写完了, requests的作者才开始推这个库。
不过urlfetch的代码比较少, 也就300+行。


链接:

 * github repo: https://github.com/lyxint/urlfetch
 * pypi: http://pypi.python.org/pypi/urlfetch
 * doc: http://packages.python.org/urlfetch/
 * blog: http://lyxint.com/archives/307



李宇杰 Yuki LEE

unread,
Apr 5, 2012, 7:29:47 AM4/5/12
to beihang-open...@googlegroups.com
相当不错!




--
Best Wishes!

Yours Sincerely,
Yuki LEE(李宇杰)


Zuyang Kou

unread,
Apr 5, 2012, 7:57:21 AM4/5/12
to beihang-open...@googlegroups.com
底层是什么呢?

2012/4/5 duyue <lyx...@gmail.com>:

--
Code is poetry.

duyue

unread,
Apr 5, 2012, 8:44:15 AM4/5/12
to beihang-open...@googlegroups.com


On Thu, Apr 5, 2012 at 7:57 PM, Zuyang Kou <lea...@gmail.com> wrote:
底层是什么呢?

python 2上是httplib
python 3上是http.client

duyue

unread,
Apr 5, 2012, 8:50:41 AM4/5/12
to beihang-open...@googlegroups.com


On Thu, Apr 5, 2012 at 7:57 PM, Zuyang Kou <lea...@gmail.com> wrote:
底层是什么呢?

最开始的时候是用python的socket模块来写的, 最后改成httplib了
测下来没有什么优势, 而且可能会存在问题

李欣越 Labi Kyo

unread,
Apr 6, 2012, 7:09:46 AM4/6/12
to beihang-open...@googlegroups.com
Nice! 墙裂支持,似乎可以方便测试api的样子。

duyue

unread,
Apr 8, 2012, 10:32:25 PM4/8/12
to beihang-open...@googlegroups.com
比requests多的一个功能就是随机填user-agent, 好把我承认我经常扒别人的网页。

把参数randua设置为False可以关闭, 或者在headers里面指定'User-Agent'。
Reply all
Reply to author
Forward
0 new messages