Python Test API - 001-安裝requests庫
阿新 • • 發佈:2018-11-14
安裝
1. 用pip安裝的:pip install requests
2. requests一直在Github上被積極開發著,路徑在 https://github.com/requests/requests
使用requests的簡單例子
import requests r = requests.get('https://api.github.com/user', auth=('user', 'pass')) print(r.status_code) print(r.headers['content-type']) print(r.encoding) print(r.text) print(r.json())
C:\Python35\python.exe D:/pyjd/djanRestPro/api/tests.py 403 application/json; charset=utf-8 utf-8 {"message":"Maximum number of login attempts exceeded. Please try again later.","documentation_url":"https://developer.github.com/v3"} {'documentation_url': 'https://developer.github.com/v3', 'message': 'Maximum number of login attempts exceeded. Please try again later.'}
Requests支援的功能:
- International Domains and URLs
- Keep-Alive & Connection Pooling
- Sessions with Cookie Persistence
- Browser-style SSL Verification
- Basic/Digest Authentication
- Elegant Key/Value Cookies
- Automatic Decompression
- Automatic Content Decoding
- Unicode Response Bodies
- Multipart File Uploads
- HTTP(S) Proxy Support
- Connection Timeouts
- Streaming Downloads
- .netrc Support
- Chunked Requests
Requests officially supports Python 2.7 & 3.4–3.6,and runs great on PyPy.