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


Python httplib.HTTP类代码示例

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


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

示例1: get_file_size

def get_file_size(url):
    types = urllib.splittype(url)
    host, res = urllib.splithost(types[1])
    h = HTTP()
    h.connect(host)
    h.putrequest('HEAD', res)
    h.putheader('Host', host)
    h.endheaders()
    status, reason, headers = h.getreply()
    return float(headers['Content-Length'])
开发者ID:games,项目名称:py-onecore,代码行数:10,代码来源:downloader.py

示例2: identify

def identify(host):
    h = HTTP(host)
    h.putrequest('GET', 'http://%s/' % host)
    h.putheader('Accept', '*/*')
    h.endheaders()
    errcode, errmsg, response = h.getreply()
    h.close()
    patterns.attempts = response.headers
    try: str = response['server']
    except: str = None
    return (str, None)
开发者ID:bruceg,项目名称:siteinfo,代码行数:11,代码来源:http.py

示例3: gethttpfile

def gethttpfile(url, size=1024*1024):
  from urllib import splithost
  from httplib import HTTP
  if not url.startswith('http:'):
    raise ValueError, "URL %s" % url
  host, selector = splithost(url[5:])
  h = HTTP(host)
  h.putrequest('GET', url)
  h.endheaders()
  h.getreply()
  res = h.getfile().read(size)
  h.close()
  return res
开发者ID:ddxofy,项目名称:hda-analyzer-mb52,代码行数:13,代码来源:hda_analyzer.py

示例4: action_delete

def action_delete():
    vip = sys.argv[3]
    h = HTTP('home.shaunkruger.com:8087')
    h.putrequest('DELETE','/module/mod_cluster_admin/vip/'+vip)
    h.putheader('Authorization','Basic '+base64.standard_b64encode('skruger:testing'))
    h.endheaders()
    errcode, errmsg, headers = h.getreply()
    if errcode == 200:
         f = h.getfile()
         print f.read()
    return
开发者ID:alepharchives,项目名称:Surrogate-Interface,代码行数:11,代码来源:surrogate_cmd_vip.py

示例5: check_url

def check_url(url):
    p = urlparse(url)
    h = HTTP(p[1])
    h.putrequest('HEAD', p[2])
    h.endheaders()
    print h.getreply()[0]
    if h.getreply()[0] == 200: return True
    else: return False                                    
开发者ID:htccsautotest,项目名称:pi_testng,代码行数:8,代码来源:testopia_util.py

示例6: checkURL

def checkURL(url):
	p = urlparse(url)
	h = HTTP(p[1])
	h.putrequest('HEAD', p[2])
	h.endheaders()
	print h.getreply()
	if h.getreply()[0] == 200: return 1
	else: return 0
开发者ID:yellowskyscraper,项目名称:Experiments,代码行数:8,代码来源:testFailThrough.py

示例7: fetch_id_from_Google

    def fetch_id_from_Google(self, cid, lac, country):
        latitude = 0
        longitude = 0
        device = "Motorola C123"
        country = Translator.Country[country]
        b_string = pack(
            ">hqh2sh13sh5sh3sBiiihiiiiii",
            21,
            0,
            len(country),
            country,
            len(device),
            device,
            len("1.3.1"),
            "1.3.1",
            len("Web"),
            "Web",
            27,
            0,
            0,
            3,
            0,
            cid,
            lac,
            0,
            0,
            0,
            0,
        )

        http = HTTP("www.google.com", 80)
        http.putrequest("POST", "/glm/mmap")
        http.putheader("Content-Type", "application/binary")
        http.putheader("Content-Length", str(len(b_string)))
        http.endheaders()
        http.send(b_string)
        code, msg, headers = http.getreply()
        try:
            bytes = http.file.read()
            (a, b, errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih", bytes)
            latitude /= 1000000.0
            longitude /= 1000000.0
            status = CellIDDBStatus.CONFIRMED
        except:
            status = CellIDDBStatus.NOT_IN_DB

        return status, latitude, longitude
开发者ID:sikopet,项目名称:imsi-catcher-detection,代码行数:47,代码来源:cellIDDatabase.py

示例8: get_redirect_url

def get_redirect_url(url):
    types = urllib.splittype(url)
    host, res = urllib.splithost(types[1])
    h = HTTP()
    h.connect(host)
    h.putrequest('HEAD', res)
    h.endheaders()
    status, reason, headers = h.getreply()
    return headers['location']
开发者ID:games,项目名称:py-onecore,代码行数:9,代码来源:downloader.py

示例9: checkUrlExists

def checkUrlExists(url):
    import httplib
    from httplib import HTTP
    from urlparse import urlparse
    
    log.debug("Checking if '" + url + "' is a URL")
    try: 
        p = urlparse(url)
        h = HTTP(p[1])
        h.putrequest('HEAD', p[2])
        h.endheaders()
        log.info("String '" + url + "' is a URL")
                
#        return h.getreply()[0] == httplib.OK
        return True
    except Exception:
        log.debug("String '" + url + "' isn't a URL")        
        return False
开发者ID:idimitrakopoulos,项目名称:fireworks,代码行数:18,代码来源:Toolkit.py

示例10: main

def main():

    cur_url = "http://zh.wikipedia.org/wiki/Category:%E9%A0%81%E9%9D%A2%E5%88%86%E9%A1%9E" #"http://zh.wikipedia.org/wiki/Wikipedia:%E5%88%86%E9%A1%9E%E7%B4%A2%E5%BC%95"
    cur_alias = "分类"
    cts = {}
    its = {} # ItemName(Wiki Item URL) : ([Alias1, Alias2, Alias3, ...], [InItemName1, InItemName, ..], [OutItemName1, OutItemName2, ..])
    h = HTTP()
    h.connect("zh.wikipedia.org")
    qcs = Queue.Queue()
    qns = Queue.Queue()
    qcs.put({"url": cur_url, "alias": cur_alias})
    #tp = ThreadPool(10)
    tds = [Thread(target=worker, args=(qcs if i % 2 else qns, qcs, qns, cts, its))
            for i in xrange(10)]

    t_start = time.time()
    for i in tds:
        i.start()
        time.sleep(5)

    for i in tds:
        i.join()
    
    #worker_c(qcs, qns, cts, its)
    #rqs = makeRequests(worker_c, args)
    #[tp.putRequest(req) for req in rqs]

    #try:
    #    tp.joinAllDismissedWorkers()
    #except KeyboardInterrupt:
    #    tp.joinAllDismissedWorkers()
    
    with open("CTS.db", "wb") as f:
        pickle.dump(cts, f)
    with open("ITS.db", "wb") as f:
        pickle.dump(its, f)

    print "CTS:", cts
    print "___________________________"
    print "ITEMS:", its
    print "Coust Time: %s" % (time.time() - t_start)
开发者ID:dreampuf,项目名称:wikipedia-word-getter,代码行数:41,代码来源:nw.py

示例11: URL_exists

def URL_exists(url):
    verbose = True
    
    ''' Checks that a URL exists (answer != 404) and returns the size.
    
    Returns None if does not exists, the size in bytes otherwise.
     ''' 
    if verbose:
        sys.stderr.write('Checking %s ' % url)
     
    p = urlparse(url) 
    h = HTTP(p[1]) 
    h.putrequest('HEAD', p[2]) 
    h.endheaders() 
    
    code, status, message = h.getreply() #@UnusedVariable

    if verbose:
        sys.stderr.write('\t%d\n' % code)
    
    
    if code == 404: 
        return None
    else: 
        return int(message['content-length'])
开发者ID:AndreaCensi,项目名称:be1008,代码行数:25,代码来源:be_materials.py

示例12: checkLink

	def checkLink(self, url):
		parsedURL = urlparse(url)
		httpConn = HTTP(parsedURL[1])
		httpConn.putrequest('HEAD',parsedURL[2])
		httpConn.endheaders()
		if httpConn.getreply()[0] == 200: return 1
		else: return 0
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:7,代码来源:checkversions.py

示例13: urlcheck

def urlcheck(url):
   u = urlparse(url)
   h = HTTP(u.geturl())
   print u.geturl()
   h.putrequest('HEAD',u.geturl())
   h.endheaders()
   r = h.getreply()
   return isvalid(r)
开发者ID:abishop42,项目名称:sample,代码行数:8,代码来源:validate.py

示例14: __makeRequest

    def __makeRequest(self, url, path):

        from httplib import HTTP

        http = HTTP(HTTP_PROXY or url.replace("http://", ""))
        http.putrequest("GET", url + path)
        http.putheader("Accept", "text/plain")
        http.endheaders()
        htcode, errmsg, headers = http.getreply()

        if htcode not in (200, 403, 404):
            raise HTTPCaptachaUnexpectedResponse(htcode, errmsg)
        # endif

        file = http.getfile()
        content = file.read()
        file.close()

        return htcode, content
开发者ID:seznam,项目名称:captcha-api,代码行数:19,代码来源:captcha.py

示例15: URL_exists

def URL_exists(url): 
	p = urlparse(url) 
	h = HTTP(p[1]) 
	h.putrequest('HEAD', p[2]) 
	h.endheaders() 
	if h.getreply()[0] == 200: 
		return True 
	else:
		return False 
开发者ID:emonson,项目名称:CopyrightScripts,代码行数:9,代码来源:get_french_copyright_docs.py


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