[英]Call REST API with authentication using Python
我是一個初學者,正在學習Python。 我想編寫一個python代碼來“調用REST API”。 您能指導我調用Rest API的步驟嗎?
我也想用Python代碼編寫curl命令。
curl -u用戶名:密碼-X GET'http: //google.com :8070/api/v2/ organizations '
如果有人可以幫助我,那將大有幫助。
謝謝
最好的選擇是使用requests
包。 使用pip install requests
進行pip install requests
。 從他們的網站上獲取的示例是:
r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
有關更多信息,請查看其文檔 。
import requests
from requests.auth import HTTPBasicAuth
requests.get("http://google.com:8070/api/v2/organizations",auth=HTTPBasicAuth('user', 'pass'))
您應該真正閱讀一些文檔並編寫一些代碼...通過一些非常快速的谷歌搜索(例如“ python http身份驗證請求”),這些事情變得非常明顯
http://docs.python-requests.org/en/master/user/authentication/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.