当前位置: 首页>>代码示例>>Python>>正文


Python httplib.IncompleteRead方法代码示例

本文整理汇总了Python中httplib.IncompleteRead方法的典型用法代码示例。如果您正苦于以下问题:Python httplib.IncompleteRead方法的具体用法?Python httplib.IncompleteRead怎么用?Python httplib.IncompleteRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在httplib的用法示例。


在下文中一共展示了httplib.IncompleteRead方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_followers

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def _check_followers(self):
        """
        Checks followers.
        """
        logging.info("Checking for new followers...")

        try:
            self.state['new_followers'] = [f_id for f_id in self.api.followers_ids(self.id) if f_id not in self.state['followers']]

            self.config['last_follow_check'] = time.time()

        except tweepy.TweepError as e:
            self._log_tweepy_error('Can\'t update followers', e)

        except IncompleteRead as e:
            self.log('Incomplete read error -- skipping followers update') 
开发者ID:thricedotted,项目名称:twitterbot,代码行数:18,代码来源:bot.py

示例2: make_request

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def make_request(url):
	try:
		req = urllib2.Request(url)
		req.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11')
		response = urllib2.urlopen(req, timeout = 60)
		link = response.read()
		response.close()
		return link
	#except httplib.IncompleteRead, e:
	#	if attempt < maxRetryAttempts:
	#		xbmc.log("Attempt {0}/{1} to load url {2}".format(attempt + 1, maxAttempts, url))
	#		return make_request_ext(url, attempt + 1)
	except urllib2.URLError, e:
		print 'We failed to open "%s".' % url
		if hasattr(e, 'code'):
			print 'We failed with error code - %s.' % e.code
		elif hasattr(e, 'reason'):
			print 'We failed to reach a server.'
			print 'Reason: ', e.reason 
开发者ID:Vashiel,项目名称:repository.adulthideout,代码行数:21,代码来源:default.py

示例3: _update_chunk_length

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def _update_chunk_length(self):
        # First, we'll figure out length of a chunk and then
        # we'll try to read it from socket.
        if self.chunk_left is not None:
            return
        line = self._fp.fp.readline()
        line = line.split(b';', 1)[0]
        try:
            self.chunk_left = int(line, 16)
        except ValueError:
            # Invalid chunked protocol response, abort.
            self.close()
            raise httplib.IncompleteRead(line) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:15,代码来源:response.py

示例4: patch_http_response_read

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def patch_http_response_read(func):
  def inner(*args):
    try:
      return func(*args)
    except httplib.IncompleteRead, e:
      return e.partial 
开发者ID:shaldengeki,项目名称:python-mal,代码行数:8,代码来源:myanimelist.py

示例5: test_chunked

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def test_chunked(self):
        chunked_start = (
            'HTTP/1.1 200 OK\r\n'
            'Transfer-Encoding: chunked\r\n\r\n'
            'a\r\n'
            'hello worl\r\n'
            '1\r\n'
            'd\r\n'
        )
        sock = FakeSocket(chunked_start + '0\r\n')
        resp = httplib.HTTPResponse(sock, method="GET")
        resp.begin()
        self.assertEqual(resp.read(), 'hello world')
        resp.close()

        for x in ('', 'foo\r\n'):
            sock = FakeSocket(chunked_start + x)
            resp = httplib.HTTPResponse(sock, method="GET")
            resp.begin()
            try:
                resp.read()
            except httplib.IncompleteRead, i:
                self.assertEqual(i.partial, 'hello world')
                self.assertEqual(repr(i),'IncompleteRead(11 bytes read)')
                self.assertEqual(str(i),'IncompleteRead(11 bytes read)')
            else:
                self.fail('IncompleteRead expected')
            finally: 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:test_httplib.py

示例6: test_incomplete_read

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def test_incomplete_read(self):
        sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n')
        resp = httplib.HTTPResponse(sock, method="GET")
        resp.begin()
        try:
            resp.read()
        except httplib.IncompleteRead as i:
            self.assertEqual(i.partial, 'Hello\r\n')
            self.assertEqual(repr(i),
                             "IncompleteRead(7 bytes read, 3 more expected)")
            self.assertEqual(str(i),
                             "IncompleteRead(7 bytes read, 3 more expected)")
            self.assertTrue(resp.isclosed())
        else:
            self.fail('IncompleteRead expected') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_httplib.py

示例7: run

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def run(self):
        '''
        S2-045 Check!
        '''
        payload = self._generatePayload()
        url = self.url
        try:
            headers = {'User-Agent': 'Mozilla/5.0', 'Content-Type': payload}
            request = urllib2.Request(url, headers=headers)
            page = urllib2.urlopen(request).read()
        except httplib.IncompleteRead, e:
            page = e.partial 
开发者ID:cyber-prog0x,项目名称:PoC-Bank,代码行数:14,代码来源:CVE-2017-5638.py

示例8: _check_mentions

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def _check_mentions(self):
        """
        Checks mentions and loads most recent tweets into the mention queue
        """
        if self._ignore_method(self.on_mention):
            logging.debug('Ignoring mentions')
            return

        try:
            current_mentions = self.api.mentions_timeline(since_id=self.state['last_mention_id'], count=100)

            # direct mentions only?
            if self.config['reply_direct_mention_only']:
                current_mentions = [t for t in current_mentions if re.split('[^@\w]', t.text)[0] == '@' + self.screen_name]

            if len(current_mentions) != 0:
                self.state['last_mention_id'] = current_mentions[0].id
            
            self.state['last_mention_time'] = time.time()

            self.state['mention_queue'] += reversed(current_mentions)

            logging.info('Mentions updated ({} retrieved, {} total in queue)'.format(len(current_mentions), len(self.state['mention_queue'])))

        except tweepy.TweepError as e:
            self._log_tweepy_error('Can\'t retrieve mentions', e)

        except IncompleteRead as e:
            self.log('Incomplete read error -- skipping mentions update') 
开发者ID:thricedotted,项目名称:twitterbot,代码行数:31,代码来源:bot.py

示例9: _check_timeline

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def _check_timeline(self):
        """
        Checks timeline and loads most recent tweets into recent timeline
        """
        if self._ignore_method(self.on_timeline):
            logging.debug('Ignoring timeline')
            return

        try:
            current_timeline = self.api.home_timeline(count=200, since_id=self.state['last_timeline_id'])

            # remove my tweets
            current_timeline = [t for t in current_timeline if t.author.screen_name.lower() != self.screen_name.lower()]

            # remove all tweets mentioning me
            current_timeline = [t for t in current_timeline if not re.search('@'+self.screen_name, t.text, flags=re.IGNORECASE)]

            if self.config['ignore_timeline_mentions']:
                # remove all tweets with mentions (heuristically)
                current_timeline = [t for t in current_timeline if '@' not in t.text]

            if len(current_timeline) != 0:
                self.state['last_timeline_id'] = current_timeline[0].id
            
            self.state['last_timeline_time'] = time.time()

            self.state['recent_timeline'] = list(reversed(current_timeline))

            logging.info('Timeline updated ({} retrieved)'.format(len(current_timeline)))

        except tweepy.TweepError as e:
            self._log_tweepy_error('Can\'t retrieve timeline', e)

        except IncompleteRead as e:
            self.log('Incomplete read error -- skipping timeline update') 
开发者ID:thricedotted,项目名称:twitterbot,代码行数:37,代码来源:bot.py

示例10: _patch_http_response_read

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def _patch_http_response_read(func):
    def inner(*args):
        try:
            return func(*args)
        except httplib.IncompleteRead, e:
            return e.partial 
开发者ID:Esri,项目名称:portalpy,代码行数:8,代码来源:portalpy.py

示例11: call_with_error_handling

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def call_with_error_handling(function, *args, **kwargs):
    """
    Calls given functions with given arguments, wrapping function call in
    try-except block catching most twitter errors and responses.
    Returns tuple: (function return value, return code). Return code is 0
    when function executes successfully. Custom Error Codes:
        1   - Unknown/Unparseable Twitter error
        2   - HTTPLib incomplete read error
        3   - SSL Read timeout error
        4   - ValeError (eg: "No JSON object could be decoded")
    """
    try:
       ret = function(*args, **kwargs)
    except TweepError as e:
        error_dict = parse_tweepy_error(e)
        logger.warning("Error {0}: {1}".format(error_dict["code"], error_dict["message"]))
        return (None, error_dict["code"])
    except IncompleteRead as i:
        logger.warn("HTTPLib incomplete read error: {0}".format(i))
        return (None, 2)
    except SSLError as s:
        logger.warn("SSL read timeout error: {0}".format(s))
        return (None, 3)
    except ValueError as v:
        logger.warn("Value error (most likely JSON problem): {0}".format(v))
        return (None, 4)

    return (ret, 0) 
开发者ID:SMAPPNYU,项目名称:smappPy,代码行数:30,代码来源:tweepy_error_handling.py

示例12: patch_http_response_read

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def patch_http_response_read(func):
    def inner(*args):
        try:
            return func(*args)
        except httplib.IncompleteRead, e:
            return e.partial 
开发者ID:scrapinghub,项目名称:exporters,代码行数:8,代码来源:s3_reader.py

示例13: tester

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import IncompleteRead [as 别名]
def tester(target):
	
	if verbose ==1:
		if message != "":
			print "Target:",target.replace("D3HYDR8%2D0wNz%2DY0U",message)
		else:
			print "Target:",target
	
	try:
		source = urllib2.urlopen("http://"+target).read()
		h = httplib.HTTPConnection(target.split('/')[0])
		try:
			h.request("GET", "/"+target.split('/',1)[1])
		except(IndexError):
			h.request("GET", "/")
		r1 = h.getresponse()
		if verbose ==1:
			print "\t[+] Response:",r1.status, r1.reason
		if re.search(alert.replace("%2D","-"), source) != None and r1.status not in range(303, 418):
			if target not in found_xss:
				if message != "":
					print "\n[!] XSS:", target.replace("D3HYDR8%2D0wNz%2DY0U",message)
				else:
					print "\n[!] XSS:", target
				print "\t[+] Response:",r1.status, r1.reason
				emails = getemails(target)
				if emails:
					print "\t[+] Email:",len(emails),"addresses\n"
					found_xss.setdefault(target, list(sets.Set(emails)))
				else:
					found_xss[target] = "None"
	except(socket.timeout, socket.gaierror, socket.error, IOError, ValueError, httplib.BadStatusLine, httplib.IncompleteRead, httplib.InvalidURL):
		pass
	except():
		pass 
开发者ID:knightmare2600,项目名称:d4rkc0de,代码行数:37,代码来源:XSSscan_v1.2.py


注:本文中的httplib.IncompleteRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。