新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python中如何調(diào)用RESTAPI接口-創(chuàng)新互聯(lián)
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)Python中如何調(diào)用REST API接口,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
本文主要介紹python中調(diào)用REST API的幾種方式,下面是python中會(huì)用到的庫。
- - urllib2
- - httplib2
- - pycurl
- - requests
urllib2
- Sample1
import urllib2, urllib github_url = 'https://api.github.com/user/repos' password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password(None, github_url, 'user', '***') auth = urllib2.HTTPBasicAuthHandler(password_manager) # create an authentication handler opener = urllib2.build_opener(auth) # create an opener with the authentication handler urllib2.install_opener(opener) # install the opener... request = urllib2.Request(github_url, urllib.urlencode({'name':'Test repo', 'description': 'Some test repository'})) # Manual encoding required handler = urllib2.urlopen(request) print handler.read()
分享文章:Python中如何調(diào)用RESTAPI接口-創(chuàng)新互聯(lián)
分享鏈接:http://ef60e0e.cn/article/dohshd.html