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的类文件对象,然后像 ...
随机推荐
- 小程序之ScrollView细节坑
Scroll-View 相信大家在使用scroll-view的时候遇到不少问题,网上也有些答案,但是类似我这个问题,貌似没搜索到答案~~ 今天媳妇问我,为什么bindscrolltolower突然不生 ...
- 【ASP.NET MVC系列】数据验证和注解
[01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作篇)(下) [04]浅谈ASP. ...
- flask WTForms源码分析及自定义WTForms
首先我们来创建一个From类 from wtforms.form import Form from wtforms import StringField from wtforms.validators ...
- from Require.js to Webpack(why)
写在前面: 本文主要参考 From Require.js to Webpack - Part 1 (the reasons),原文作者将项目从 require.js 转移到了 webpack 并详细说 ...
- [bzoj1826] [JSOI2010]缓存交换
虽然不知道为什么..但显然,每次扔掉离下次查询最远的内存单元就行了233 用堆来维护贪心...(优先队列大法好 #include<cstdio> #include<iostream& ...
- [bzoj1914] [Usaco2010 OPen]Triangle Counting 数三角形
跑去看了黄学长的题解.. 第一次听说级角排序= =因为一直见计算几何就跑= = 级角排序就是按 原点和点连起来的边 与x轴正半轴构成的角的角度 排序...排序完效果就是逆时针旋转地枚举每个点. 要求的 ...
- Number Sequence(快速幂矩阵)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...
- UnityShader 表面着色器简单例程集合
0.前言 这些简单的shader程序都是写于2015年的暑假.当时实验室空调坏了,30多个人在实验室中挥汗如雨,闷热中学习shader的日子还历历在目.这些文章闲置在我个人博客中,一年将过,师弟也到了 ...
- linux 下CentOS 下 npm命令安装gitbook失败的问题
运行环境 linux 服务器:CentOS 7.0 系统:安装了nodejs :使用 npm 安装 gitbook 出现错误提示: npm install -g gitbook-cli symbol ...
- linux安装navicat全程记录
国庆期间自己在试着用linux(ubuntu),献上navicat安装方法,以及很多教程里没有写的一些小东西 step1: 去navicat官网下载安装包,网址:http://www.navicat. ...