使用 requests, 已有安裝 requests 但執行程式會錯誤,訊息:
Error: No module named ‘requests.packages’
解法:
pip install chardet2 urllib3
新的錯誤訊息:
Error: Requests dependency 'chardet' must be version >= 3.0.2, < 3.1.0!
造成錯誤的程式碼:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
解法:上面程式換成:
from urllib3.exceptions import InsecureRequestWarning warnings.simplefilter('ignore',InsecureRequestWarning)
相關文章:
requests 使用方法:
https://requests.readthedocs.io/en/master/
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass')) >>> r.status_code 200 >>> r.headers['content-type'] 'application/json; charset=utf8' >>> r.encoding 'utf-8' >>> r.text u'{"type":"User"...' >>> r.json() {u'private_gists': 419, u'total_private_repos': 77, ...}