Python中如何调用RESTAPI接口-创新互联
这期内容当中小编将会给大家带来有关Python中如何调用REST API接口,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
本文主要介绍python中调用REST API的几种方式,下面是python中会用到的库。
- - 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中如何调用RESTAPI接口-创新互联
转载来于:http://pcwzsj.com/article/dohshd.html