test for python urllib
#!/usr/bin/python import urllib2
import time
import logging
import threading succCount = 0
failCount = 0
IP = '127.0.0.1'
port = ''
postUrl = "http://%s:%s/" % (IP, port)
HTTP_POST_HEADERS = {'Content-Type': 'text/xml'} content = ' ' logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
filename='myapp.log',
filemode='w') def doPost1(postUrl,postHeaders,postData = None):
global succCount,failCount
postReq = urllib2.Request(url=postUrl, headers=postHeaders, data=postData)
try:
response = urllib2.urlopen(postReq, timeout=3)
except urllib2.HTTPError,e:
failCount += 1
logging.debug("catch HTTPError")
logging.error("The server couldn\'t fulfill the request")
logging.error("Error code: %d",e.code)
logging.error("Error reason: %s",e.reason)
except urllib2.URLError,e:
failCount += 1
logging.debug("catch URLError")
logging.error("We failed to reach a server")
logging.error("Reason: %s", e.reason)
else:
succCount += 1
logging.debug("success to recv response")
logging.info("response content =%s", response.read())
logging.info("response code =%s", response.getcode())
logging.info("contentType =%s" , response.info().getheader("Content-Type"))
logging.info("response url =%s", response.geturl())
logging.info("response info =\n%s", response.info()) def doPost2(postUrl,postHeaders,postData):
for j in range(0, 1):
doPost1(postUrl,postHeaders,postData)
time.sleep(0.001) if __name__ == "__main__": logging.info('begin test') threadinggroup = []
for i in range(0, 1):
tt = threading.Thread(target = doPost2,args = (postUrl, HTTP_POST_HEADERS,content))
tt.start()
threadinggroup.append(tt) for tt in threadinggroup:
tt.join() logging.info('succCount = %d ,failCount = %d',succCount,failCount)
test for python urllib的更多相关文章
- python urllib模块的urlopen()的使用方法及实例
Python urllib 库提供了一个从指定的 URL 地址获取网页数据,然后对其进行分析处理,获取想要的数据. 一.urllib模块urlopen()函数: urlopen(url, data=N ...
- Python:urllib和urllib2的区别(转)
原文链接:http://www.cnblogs.com/yuxc/ 作为一个Python菜鸟,之前一直懵懂于urllib和urllib2,以为2是1的升级版.今天看到老外写的一篇<Python: ...
- Python urllib和urllib2模块学习(一)
(参考资料:现代魔法学院 http://www.nowamagic.net/academy/detail/1302803) Python标准库中有许多实用的工具类,但是在具体使用时,标准库文档上对使用 ...
- python urllib和urllib2 区别
python有一个基础的库叫httplib.httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,urllib2)使用了它的http实现 ...
- Python urllib urlretrieve函数解析
Python urllib urlretrieve函数解析 利用urllib.request.urlretrieve函数下载文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 Ur ...
- python+urllib+beautifulSoup实现一个简单的爬虫
urllib是python3.x中提供的一系列操作的URL的库,它可以轻松的模拟用户使用浏览器访问网页. Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能 ...
- HTTP Header Injection in Python urllib
catalogue . Overview . The urllib Bug . Attack Scenarios . 其他场景 . 防护/缓解手段 1. Overview Python's built ...
- python urllib urllib2
区别 1) urllib2可以接受一个Request类的实例来设置URL请求的headers,urllib仅可以接受URL.这意味着,用urllib时不可以伪装User Agent字符串等. 2) u ...
- python urllib基础学习
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #使用python创建一个简单的WEB客户端 import urll ...
- python urllib模块
1.urllib.urlopen(url[,data[,proxies]]) urllib.urlopen(url[, data[, proxies]]) :创建一个表示远程url的类文件对象,然后像 ...
随机推荐
- js上传图片
额 呆坐许久 感觉 有很多想写的 就是不知从何写起..贼尴尬. 其实 我平时项目中 基本上传图片什么的 都是跟着from 表单 一起提交给后台的 实行起来 简单暴力 连图片预览的都没有写 ...
- jsp分页
<%! int pataSize=5;// 每页多少数据 int totalCount =0; //数据共多少 int pageCount = 0; ///数据共有多少页 ...
- DAY3-“忙里偷闲”找你玩耍2018-1-11
接触Java第三天,嘿嘿,今天近代史期末考试,提前一小时交卷,回宿舍继续学习,中午去见女神姐姐了,每次见完女神姐姐都是满满地动力.这次女神姐姐告诉我们要好好规划自己的时间,早上花20分钟规划好一天的时 ...
- SharePoint2013上传列表模板(后缀stp)
在根网站操作
- java_web学习(五) JSTL标准标签库
1.什么是JSTL JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. ...
- HttpClient 模拟发送Post和Get请求 并用fastjson对返回json字符串数据解析,和HttpClient一些参数方法的deprecated(弃用)的综合总结
最近在做一个接口调用的时候用到Apache的httpclient时候,发现引入最新版本4.5,DefaultHttpClient等老版本常用的类已经过时了,不推荐使用了:去官网看了一下在4.3之后就抛 ...
- Java与算法之(5) - 老鼠走迷宫(深度优先算法)
小老鼠走进了格子迷宫,如何能绕过猫并以最短的路线吃到奶酪呢? 注意只能上下左右移动,不能斜着移动. 在解决迷宫问题上,深度优先算法的思路是沿着一条路一直走,遇到障碍或走出边界再返回尝试别的路径. 首先 ...
- 数据结构之链表-链表实现及常用操作(C++篇)
数据结构之链表-链表实现及常用操作(C++篇) 0.摘要 定义 插入节点(单向链表) 删除节点(单向链表) 反向遍历链表 找出中间节点 找出倒数第k个节点 翻转链表 判断两个链表是否相交,并返回相交点 ...
- hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )
#1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...