0
回答
python urllib2 open请求处理重定向失败,大神帮忙看看
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

同意的代码,请求第一个成功,请求第二个报超时,有谁知道是什么原因吗

http://qt.qq.com/php_cgi/group_comm/hero_moment/common/php/share_video.php?game_id=2103041&vid=1117e5db85554409a373f34edd9e7ec5&type=weibo

http://qt.qq.com/php_cgi/group_comm/hero_moment/common/php/share_video.php?game_id=2103041&vid=1117e5db85554409a373f34edd9e7ec5&type=sina

都有是302的,请大神指点

class MyTest:
    version = '1.0.0'
    rootUrl = 'http://qt.qq.com/'
    urlOpener = None
    def __init__(self,rootUrl = None):
        if(rootUrl != None):
            self.rootUrl = rootUrl
        
        self.urlOpener = build_opener(HTTPCookieProcessor())
        self.SetTimeout(15)
        # disable http proxy handler to avoid slow performance
        for h in self.urlOpener.handle_open["http"]:
            if isinstance(h, ProxyHandler):
                self.urlOpener.handle_open["http"].remove(h)
				
    def _do_http_request(self, resource, data=None, isFullUrl=False):
        #space in www can be replace by '%20'
        resource = resource.replace(" ", "%20")
        if(isFullUrl is False):
            url = self.rootUrl + resource
        else:
            url = resource
			
        LogInfo("Http Url: " + url)
        LogInfo("Http Request Body: " + str(data))
        request = Request(url)
        request.add_header("Content-type", "application/x-www-form-urlencoded; charset=UTF-8")
        request.add_header("Referer","http://bbs.lol.qq.com/forum.php")  
		
        response = None
        code = ''
        msg = ''
        resData = ''
        try:
            response = self.urlOpener.open(request, data,20)
            code = str(response.code)
            msg = str(response.msg)
            resData = response.read()
        except Exception, e:
            exstr = traceback.format_exc()
            print exstr
        if response != None:
            response.close()
        LogInfo('Http Response Status/Message: ' + code + " " + msg)
        LogInfo('Http Response Body: ' + resData)
        return resData, code, msg


if __name__ == '__main__':
    test = MyTest('http://qt.qq.com/')
    result=test.qtweb_request_with_code('php_cgi/group_comm/hero_moment/common/php/share_video.php?game_id=2103041&vid=1117e5db85554409a373f34edd9e7ec5&type=sina')
    print(result[0])





举报
aikede
发帖于2年前 0回/500阅
顶部