本文整理汇总了Python中httplib.HTTP.putrequest方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.putrequest方法的具体用法?Python HTTP.putrequest怎么用?Python HTTP.putrequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib.HTTP
的用法示例。
在下文中一共展示了HTTP.putrequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkLink
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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
示例2: checkURL
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
def checkURL(url):
p = urlparse(url)
h = HTTP(p[1])
h.putrequest('HEAD', p[2])
h.endheaders()
if h.getreply()[0] == 200: return 1
else: return 0
示例3: run
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
def run(self):
try:
self.downloaded = os.path.getsize(self.filename)
except OSError:
self.downloaded = 0
self.start_pointer = self.ranges[0] + self.downloaded
if self.start_pointer >= self.ranges[1]:
print '%s has been over.' % self.filename
return
types = urllib.splittype(self.url)
host, res = urllib.splithost(types[1])
h = HTTP()
h.connect(host)
h.putrequest('GET', res)
h.putheader('Host', host)
h.putheader('Range', "bytes=%d-%d" % (self.start_pointer, self.ranges[1]))
h.endheaders()
response = h._conn.getresponse()
data = response.read(self.once_buffer)
while data:
file_opener = open(self.filename, 'ab+')
file_opener.write(data)
file_opener.close()
self.downloaded += len(data)
data = response.read(self.once_buffer)
h.close()
示例4: doLookup
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
def doLookup(cellId, lac, host="www.google.com", port=80):
from string import replace
from struct import unpack
page = "/glm/mmap"
http = HTTP(host, port)
result = None
errorCode = 0
content_type, body = encode_request(cellId, lac)
http.putrequest('POST', page)
http.putheader('Content-Type', content_type)
http.putheader('Content-Length', str(len(body)))
http.endheaders()
http.send(body)
errcode, errmsg, headers = http.getreply()
result = http.file.read()
# be nice to the web service, will not pause on memoized coordinates
time.sleep(0.75)
# could need some modification to get the answer: here I just need
# to get the 5 first characters
if (errcode == 200):
(a, b, errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih",result)
latitude = latitude / 1000000.0
longitude = longitude / 1000000.0
return latitude, longitude
示例5: URL_exists
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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'])
示例6: check_url
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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
示例7: urlcheck
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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)
示例8: URL_exists
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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
示例9: grab_information
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
def grab_information(cid, lac, mnc=0, mcc=0):
country = country_iso(mcc)
v("Fetching latitude and longitude...")
query = 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, int(cid), int(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(query)))
http.endheaders()
http.send(query)
code, msg, headers = http.getreply()
result = http.file.read()
try:
(a, b,errorCode, lat, lon, cov, d, e) = unpack(">hBiiiiih",result)
except:
a = 0
b = 0
errorCode = 0
lat = 0
lon = 0
cov = 0
d = 0
e = 0
pass
v("a=%s, b=%s, errorCode=%s, cov=%s, d=%s, e=%s" % (str(a), str(b), errorCode, str(cov), str(d), str(e)))
lat = lat / 1000000.0
lon = lon / 1000000.0
v("Here we go: %s and %s" % (lat, lon))
geo_info = None
geo_info_json = None
geo_info = grab_geo_info(lat, lon)
geo_info = grab_geo_info(-8.064159, -34.896666)
print str(geo_info)
geo_info_json = json.loads(geo_info)
v("Geo Info: %s" % geo_info)
v("Geo Info: %s" % str(geo_info_json))
c = Cell(geo_info_json, lat, lon, cov)
return c
示例10: get_redirect_url
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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']
示例11: fetch_latlong_http
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
def fetch_latlong_http(query):
http = HTTP("www.google.com", 80)
http.putrequest("POST", "/glm/mmap")
http.putheader("Content-Type", "application/binary")
http.putheader("Content-Length", str(len(query)))
http.endheaders()
http.send(query)
code, msg, headers = http.getreply()
result = http.file.read()
return result
示例12: fetch_latlong_http
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
def fetch_latlong_http(self, query):
http = HTTP('www.google.com', 80)
http.putrequest('POST', '/glm/mmap')
http.putheader('Content-Type', 'application/binary')
http.putheader('Content-Length', str(len(query)))
http.endheaders()
http.send(query)
code, msg, headers = http.getreply()
result = http.file.read()
return result
示例13: get_file_size
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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'])
示例14: action_delete
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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
示例15: identify
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putrequest [as 别名]
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)