本文整理汇总了Python中httplib.HTTP.putheader方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.putheader方法的具体用法?Python HTTP.putheader怎么用?Python HTTP.putheader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib.HTTP
的用法示例。
在下文中一共展示了HTTP.putheader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doLookup
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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
示例2: run
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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()
示例3: grab_information
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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
示例4: fetch_latlong_http
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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
示例5: get_file_size
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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'])
示例6: fetch_latlong_http
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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
示例7: action_delete
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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
示例8: identify
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [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)
示例9: fetch_id_from_Google
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
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
示例10: _post_multipart
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
def _post_multipart(self, host, selector, fields, files):
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return the server's response page.
"""
content_type, body = self._encode_multipart_formdata(files)
h = HTTP(host)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
h.send(body)
errcode, errmsg, headers = h.getreply()
logger.debug("File sent with error code " + str(errcode) + "; Message was: " + str(errmsg))
return RequestResult(errcode, errmsg, h.file.read())
示例11: RetrieveAsFile
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
def RetrieveAsFile(self, host, path=''):
from httplib import HTTP
try:
h = HTTP(host)
except:
self.logprint("Failed to create HTTP connection to %s... is the network available?" % (host))
return None
h.putrequest('GET',path)
h.putheader('Accept','text/html')
h.putheader('Accept','text/plain')
h.endheaders()
errcode, errmsg, headers = h.getreply()
if errcode != 200:
self.logprint("HTTP error code %d: %s" % (errcode, errmsg))
return None
f = h.getfile()
return f
示例12: doLookup
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
def doLookup(cellId, lac, host = "www.google.com", port = 80):
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()
if (errcode == 200):
(a, b,errorCode, latitude, longitude, accuracy, c, d) = unpack(">hBiiiiih",result)
latitude = latitude / 1000000.0
longitude = longitude / 1000000.0
return latitude, longitude, accuracy
示例13: __makeRequest
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
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
示例14: action_list
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
def action_list():
h = HTTP(surrogate_conf.get('hostname'))
h.putrequest('GET','/module/mod_cluster_admin/vip')
userpass = "%s:%s" % (surrogate_conf.get('username'),surrogate_conf.get('password'))
h.putheader('Authorization','Basic '+base64.standard_b64encode(userpass))
h.endheaders()
errcode, errmsg, headers = h.getreply()
if errcode == 200:
f = h.getfile()
data= f.read()
vip = json.loads(data) # Convert json string to python array object
formatstr = "%-35s %-8s %s" # reusable format string for header and data output lines
print formatstr % ("Address", "Status","Nodes")
print "==============================================================================="
for v in vip["items"]:
print formatstr % (v["address"], v["status"],v["nodes"])
elif errcode == 401:
print "Authentication error."
else:
print "HTTP %s: %s" % (errcode,errmsg)
return
示例15: post_multipart
# 需要导入模块: from httplib import HTTP [as 别名]
# 或者: from httplib.HTTP import putheader [as 别名]
def post_multipart(host, port, selector, fields, files):
content_type, body = encode_multipart_formdata(fields, files)
h = HTTPConnection(host, port)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
if _python2:
h.send(body)
else:
h.send(body.encode('utf-8'))
if _python2:
errcode, errmsg, headers = h.getreply()
if errcode != 200:
raise HTTPException("%s: %s" % (errcode, errmsg))
return h.file.read()
else:
res = h.getresponse()
if res.status != 200:
raise HTTPException("%s: %s" % (res.status, res.reason))
return res.read()