mirror of
https://github.com/apachecn/ailearning.git
synced 2026-04-24 02:23:45 +08:00
2020-10-19 21:08:55
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
In [1]:
|
||||
|
||||
```
|
||||
```py
|
||||
import requests
|
||||
|
||||
```
|
||||
@@ -13,7 +13,7 @@ Python 标准库中的 `urllib2` 模块提供了你所需要的大多数 `HTTP`
|
||||
|
||||
In [2]:
|
||||
|
||||
```
|
||||
```py
|
||||
r = requests.get("http://httpbin.org/get")
|
||||
r = requests.post('http://httpbin.org/post', data = {'key':'value'})
|
||||
r = requests.put("http://httpbin.org/put")
|
||||
@@ -29,7 +29,7 @@ r = requests.options("http://httpbin.org/get")
|
||||
|
||||
In [3]:
|
||||
|
||||
```
|
||||
```py
|
||||
payload = {'key1': 'value1', 'key2': 'value2'}
|
||||
r = requests.get("http://httpbin.org/get", params=payload)
|
||||
|
||||
@@ -39,12 +39,12 @@ r = requests.get("http://httpbin.org/get", params=payload)
|
||||
|
||||
In [4]:
|
||||
|
||||
```
|
||||
```py
|
||||
print(r.url)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
http://httpbin.org/get?key2=value2&key1=value1
|
||||
|
||||
```
|
||||
@@ -55,14 +55,14 @@ http://httpbin.org/get?key2=value2&key1=value1
|
||||
|
||||
In [5]:
|
||||
|
||||
```
|
||||
```py
|
||||
r = requests.get('https://github.com/timeline.json')
|
||||
|
||||
print r.text
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
{"message":"Hello there, wayfaring stranger. If you’re reading this then you probably didn’t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.","documentation_url":"https://developer.github.com/v3/activity/events/#list-public-events"}
|
||||
|
||||
```
|
||||
@@ -71,14 +71,14 @@ print r.text
|
||||
|
||||
In [6]:
|
||||
|
||||
```
|
||||
```py
|
||||
r.encoding
|
||||
|
||||
```
|
||||
|
||||
Out[6]:
|
||||
|
||||
```
|
||||
```py
|
||||
'utf-8'
|
||||
```
|
||||
|
||||
@@ -86,7 +86,7 @@ Out[6]:
|
||||
|
||||
In [7]:
|
||||
|
||||
```
|
||||
```py
|
||||
r.encoding = "ISO-8859-1"
|
||||
|
||||
r.text
|
||||
@@ -95,7 +95,7 @@ r.text
|
||||
|
||||
Out[7]:
|
||||
|
||||
```
|
||||
```py
|
||||
u'{"message":"Hello there, wayfaring stranger. If you\xe2\x80\x99re reading this then you probably didn\xe2\x80\x99t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.","documentation_url":"https://developer.github.com/v3/activity/events/#list-public-events"}'
|
||||
```
|
||||
|
||||
@@ -103,14 +103,14 @@ u'{"message":"Hello there, wayfaring stranger. If you\xe2\x80\x99re reading this
|
||||
|
||||
In [8]:
|
||||
|
||||
```
|
||||
```py
|
||||
r.json()
|
||||
|
||||
```
|
||||
|
||||
Out[8]:
|
||||
|
||||
```
|
||||
```py
|
||||
{u'documentation_url': u'https://developer.github.com/v3/activity/events/#list-public-events',
|
||||
u'message': u'Hello there, wayfaring stranger. If you\xe2\x80\x99re reading this then you probably didn\xe2\x80\x99t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.'}
|
||||
```
|
||||
@@ -121,7 +121,7 @@ Out[8]:
|
||||
|
||||
In [9]:
|
||||
|
||||
```
|
||||
```py
|
||||
r = requests.get('http://httpbin.org/get')
|
||||
|
||||
r.status_code
|
||||
@@ -130,7 +130,7 @@ r.status_code
|
||||
|
||||
Out[9]:
|
||||
|
||||
```
|
||||
```py
|
||||
407
|
||||
```
|
||||
|
||||
@@ -138,13 +138,13 @@ Out[9]:
|
||||
|
||||
In [10]:
|
||||
|
||||
```
|
||||
```py
|
||||
r.headers['Content-Type']
|
||||
|
||||
```
|
||||
|
||||
Out[10]:
|
||||
|
||||
```
|
||||
```py
|
||||
'text/html'
|
||||
```
|
||||
Reference in New Issue
Block a user