本文整理汇总了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'])
示例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)
示例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
示例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
示例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
示例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
示例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
示例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']
示例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
示例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)
示例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'])
示例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
示例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)
示例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
示例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