#!/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的更多相关文章

  1. python urllib模块的urlopen()的使用方法及实例

    Python urllib 库提供了一个从指定的 URL 地址获取网页数据,然后对其进行分析处理,获取想要的数据. 一.urllib模块urlopen()函数: urlopen(url, data=N ...

  2. Python:urllib和urllib2的区别(转)

    原文链接:http://www.cnblogs.com/yuxc/ 作为一个Python菜鸟,之前一直懵懂于urllib和urllib2,以为2是1的升级版.今天看到老外写的一篇<Python: ...

  3. Python urllib和urllib2模块学习(一)

    (参考资料:现代魔法学院 http://www.nowamagic.net/academy/detail/1302803) Python标准库中有许多实用的工具类,但是在具体使用时,标准库文档上对使用 ...

  4. python urllib和urllib2 区别

    python有一个基础的库叫httplib.httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,urllib2)使用了它的http实现 ...

  5. Python urllib urlretrieve函数解析

    Python urllib urlretrieve函数解析 利用urllib.request.urlretrieve函数下载文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 Ur ...

  6. python+urllib+beautifulSoup实现一个简单的爬虫

    urllib是python3.x中提供的一系列操作的URL的库,它可以轻松的模拟用户使用浏览器访问网页. Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能 ...

  7. HTTP Header Injection in Python urllib

    catalogue . Overview . The urllib Bug . Attack Scenarios . 其他场景 . 防护/缓解手段 1. Overview Python's built ...

  8. python urllib urllib2

    区别 1) urllib2可以接受一个Request类的实例来设置URL请求的headers,urllib仅可以接受URL.这意味着,用urllib时不可以伪装User Agent字符串等. 2) u ...

  9. python urllib基础学习

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #使用python创建一个简单的WEB客户端 import urll ...

  10. python urllib模块

    1.urllib.urlopen(url[,data[,proxies]]) urllib.urlopen(url[, data[, proxies]]) :创建一个表示远程url的类文件对象,然后像 ...

随机推荐

  1. 【单调栈】最长不上升子序列变式,洛谷 P2757 导弹的召唤

    题目背景 易琢然今天玩使命召唤,被敌军用空对地导弹轰炸,很不爽:众所周知,易琢然很不老实,他开了外挂: 外挂第一次可以打掉任意高度的导弹,之后每一次都不能打掉大于上一次高度的导弹: 但易琢然水平太差, ...

  2. 大话python模块与包

    前言 眼看着老掌门年纪越来越大,掌门之位的传承也成了门派中的一件大事.这天,老掌门把小掌门叫到跟前,语重心长地说道:孩子啊,以后你就要继任掌门之位了,我就传授此生所学的绝世功法与你,以后可要悉心学习, ...

  3. oracle之 dblink 报ORA-03113 TNS-12543

    -- 客户端使用含 dblink sql报错( 症状:当数据库使用dblink访问其他数据库时,第一次执行某条dblink sql大多数情况下可以成功,偶尔执行一段时间后报错.如果该会话空闲二十分钟以 ...

  4. MYSQL数据库表按月备份,滚动,保留6次备份

    要求: 每月1日0点:在不影响业务的情况下,备份整月的数据,保留6次备份. 思路: 基于MYSQL事件功能,每月按时完成操作 RENAME语句具有原子性,新旧表无缝切换 RENAME语句仅修改表定义, ...

  5. 微信小程序——Now you can provide attr "wx:key" for a "wx:for" to improve performance.

    在官方的swiper(滑块视图容器)中demo代码,运行时会出现Now you can provide attr "wx:key" for a "wx:for" ...

  6. 获取 JavaScript 异步函数返回值的笔记

    wrong action function asyncfunc() { let ret = 100; setTimeout(() => { return ret; }, 1000) } let ...

  7. contain_of宏定义

    Container_of在Linux内核中是一个常用的宏,用于从包含在某个结构中的指针获得结构本身的指针,通俗地讲就是通过结构体变量中某个成员的首地址进而获得整个结构体变量的首地址. 实现方式: co ...

  8. 【转】Memory gates checking failed because the free memory***解决办法

    Issue: Vault users cannot connect. VLOGS show the following error: Memory gates checking failed beca ...

  9. 基于Windows下处理Java错误:编码GBK的不可映射字符的解决方案

    基于Windows下处理Java错误:编码GBK的不可映射字符的解决方案 最近在研究Java,涉及命令行编译,使用notepad++编辑器,然后使用javac编译: 之前的几个文件没有中文的内容,都没 ...

  10. bzoj:3085: 反质数加强版SAPGAP

    Description 先解释一下SAPGAP=Super AntiPrime, Greatest AntiPrime(真不是网络流),于是你就应该知道本题是一个关于反质数(Antiprime)的问题 ...