Skip to content

Commit 0aaa25a

Browse files
committed
增加 Requests
1 parent 70b8a82 commit 0aaa25a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

libs/python.wiki

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,27 @@ page = handle.read()
394394
handle.close()
395395
</source>
396396

397+
<h4>Requests</h4>
398+
399+
Home:[http://www.python-requests.org/]
400+
401+
这是一个用起来很优雅的库,如其名,封装了 HTTP 请求的功能。
402+
403+
代码示例
404+
<source lang="python">
405+
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
406+
>>> r.status_code
407+
200
408+
>>> r.headers['content-type']
409+
'application/json; charset=utf8'
410+
>>> r.encoding
411+
'utf-8'
412+
>>> r.text
413+
u'{"type":"User"...'
414+
>>> r.json()
415+
{u'private_gists': 419, u'total_private_repos': 77, ...}
416+
</source>
417+
397418
== 4.2 HTTP Server ==
398419

399420
<h4>SimpleHTTPServer & http.server</h4>

0 commit comments

Comments
 (0)