'''
http://httpbin.org/
http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
http://docs.python-requests.org/en/master/
上傳檔案 & Cookie & 不合格憑證
https://zwindr.blogspot.com/2016/08/python-requests.html
'''
import requests
print('======增加 URL 查詢參數')
# 查詢參數
my_params = {'q': 'bugsfamily'}
# 將查詢參數加入 GET 請求中
r = requests.get('https://www.google.com/search', params = my_params, timeout = 3)
re = r.status_code
print('status_code:',re)
print('headers:',r.headers['content-type'])
print('encoding:',r.encoding)
print('TEXT Count bugsfamily Nun:',r.text.count('bugsfamily'))
if r.status_code == requests.codes.ok:
print("OK")
else:
print(type(requests.codes.ok))
r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
re = r.status_code
print('status_code:',re)
print('headers:',r.headers['content-type'])
print('encoding:',r.encoding)
print('TEXT:',r.text)
re = r.json()
print('JSON:',re['message'])
if r.status_code == 200:
print("OK")
else:
print('Notes:',r.status_code)