xiyushiyi的专栏

唧唧复唧唧

python 通过urllib 访问api接口

其中的poster可以通过pip安装


# encoding: utf-8
import urllib
import urllib2
import logging
import ssl
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers

log_file = 'interface_test.log'
logging.basicConfig(filename = log_file,level =logging.DEBUG,format='%(asctime)s %(levelname)s %(message)s')
type = 1
register_openers()
datagen, headers = multipart_encode({'username':'admin','password':'nsfocus0','format':'json'})
#datagen, headers = multipart_encode({"taskField": open("config_xml/192.168.56.1_66c221be-6ab2-ef53-1589-fe16877914e2_chk.xml", "rb"),'format':'xml'})
request = urllib2.Request("https://ip/api/path/23", datagen, headers)

response = urllib2.urlopen(request).read()
logging.debug('result of task create by configfile:%s' % response)
print response


阅读更多
上一篇Python 验证手机号码和邮箱
下一篇Spring Boot(一):项目环境搭建
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭