Python3處理HTTP請求的實(shí)例
Python3處理HTTP請求的包:http.client,urllib,urllib3,requests
其中,http 比較 low-level,一般不直接使用
urllib更 high-level一點(diǎn),屬于標(biāo)準(zhǔn)庫。urllib3跟urllib類似,擁有一些重要特性而且易于使用,但是屬于擴(kuò)展庫,需要安裝
requests 基于urllib3 ,也不是標(biāo)準(zhǔn)庫,但是使用非常方便
個人感覺,如果非要用標(biāo)準(zhǔn)庫,就使用urllib。如果沒有限制,就用requests
# import http.client
# http_client = http.client.HTTPConnection('localhost',8080,timeout=10)
# http_client.request('get','/jenkins/api/json?pretty=true')
# response = http_client.getresponse()
# print(response.status)
# print(response.read())
# import urllib.request
# response = urllib.request.urlopen('http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status)
# print(response.read())
# import urllib3
# response = urllib3.PoolManager().request('get','http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status)
# import requests
# response = requests.get('http://localhost:8080/jenkins/api/json?pretty=true')
# print(response.status_code)
# print(response.text)
# print(response.json())
# print(response.reason)
import requests
from requests.auth import HTTPBasicAuth
response = requests.post('http://localhost:8080/jenkins/job/check_python_version/build',auth=('admin','wangmin'))
print (response.status_code)
print (response.reason)
print(response.headers)
jenkins系統(tǒng)管理=》Configure Global Security,取消勾選“防止跨站點(diǎn)請求偽造”

以上這篇Python3處理HTTP請求的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python中的numpy數(shù)組維度擴(kuò)展詳解
這篇文章主要介紹了Python中的numpy數(shù)組維度擴(kuò)展詳解,在numpy數(shù)組中,切片功能非常常用,例如x[:]表示取x的所有元素,可以通過在切片中增加None或者np.newaxis實(shí)現(xiàn),它們的作用就是在相應(yīng)的位置上增加一個維度,在這個維度上只有一個元素,需要的朋友可以參考下2023-09-09
Pytorch - TORCH.NN.INIT 參數(shù)初始化的操作
這篇文章主要介紹了Pytorch - TORCH.NN.INIT 參數(shù)初始化的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-02-02
python統(tǒng)計mysql數(shù)據(jù)量變化并調(diào)用接口告警的示例代碼
這篇文章主要介紹了python統(tǒng)計mysql數(shù)據(jù)量變化并調(diào)用接口告警的示例代碼,幫助大家更好的利用python操作數(shù)據(jù)庫,感興趣的朋友可以了解下2020-09-09

