python 通过urllib 访问api接口
2015-11-19 15:46
531 查看
其中的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 -- 类定义的讲解
- python---raw_input()和input()输入区别
- python logging模块实例
- [置顶] Python在线爆破邮箱账号密码测试代码(亲测可用)
- python3.5-ssh免输入密码过程
- Python模拟登陆(使用requests库)
- python 文件输出与重定向 ,输出的内容会在内存中暂存,不会立刻输出到文件中
- python连接Hbase
- Python爬虫——爬取网站的图片
- Python基础(函数)
- 第一个python实例
- python切片
- python开源项目目录结构参考
- 流程控制练习*找奇数-求和-求积
- python里的map和reduce
- python学习笔记
- ---Maya&Python---001---
- Python基础学习-MySQL与Python结合
- Python 基础知识学习
- Python循环语句