本文整理汇总了Python中request.Request.open方法的典型用法代码示例。如果您正苦于以下问题:Python Request.open方法的具体用法?Python Request.open怎么用?Python Request.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request.Request
的用法示例。
在下文中一共展示了Request.open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pub_uuid
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import open [as 别名]
def get_pub_uuid(self, hw_uuid, host):
try:
pub_uuid = self._config.get(_SECTION, _get_option_name(hw_uuid, host))
logging.info('Public UUID "%s" read from database' % pub_uuid)
return pub_uuid
except ConfigParser.NoOptionError:
try:
req = Request('/client/pub_uuid/%s' % self.get_priv_uuid())
pudict = json.loads(req.open().read())
self.set_pub_uuid(self.hw_uuid, Request(), pudict['pub_uuid'])
return pudict['pub_uuid']
except Exception, e:
error(_('Error determining public UUID: %s') % e)
sys.stderr.write(_("Unable to determine Public UUID! This could be a network error or you've\n"))
sys.stderr.write(_("not submitted your profile yet.\n"))
raise PubUUIDError, 'Could not determine Public UUID!\n'
示例2: rating
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import open [as 别名]
def rating(profile, smoonURL):
print ""
print _("Current rating for vendor/model.")
print ""
req = Request('/client/host_rating?vendor=%s&system=%s' % (urllib.quote(hardware().host.systemVendor),
urllib.quote(hardware().host.systemModel)))
r = json.load(req.open())['ratings']
rating_system = { '0' : _('Unrated/Unknown'),
'1' : _('Non-working'),
'2' : _('Partially-working'),
'3' : _('Requires 3rd party drivers'),
'4' : _('Works, needs additional configuration'),
'5' : _('Works out of the box')
}
print "\tCount\tRating"
print "\t-----------------"
for rate in r:
print "\t%s\t%s" % (r[rate], rating_system[rate])
示例3: scan
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import open [as 别名]
def scan(profile, smoonURL):
print _("Scanning %s for known errata.\n" % smoonURL)
devices = []
for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in hardware().deviceIter():
if VendorID:
devices.append('%s/%04x/%04x/%04x/%04x' % (Bus,
int(VendorID or 0),
int(DeviceID or 0),
int(SubsysVendorID or 0),
int(SubsysDeviceID or 0)) )
searchDevices = 'NULLPAGE'
devices.append('System/%s/%s' % ( urllib.quote(hardware().host.systemVendor), urllib.quote(hardware().host.systemModel) ))
for dev in devices:
searchDevices = "%s|%s" % (searchDevices, dev)
try:
req = Request('/smolt-w/api.php')
req.add_data('action=query&titles=%s&format=json' % searchDevices)
r = json.load(req.open())
except urllib2.HTTPError:
print "Could not wiki for errata!"
return
found = []
for page in r['query']['pages']:
try:
if int(page) > 0:
found.append('\t%swiki/%s' % (smoonURL, r['query']['pages'][page]['title']))
except KeyError:
pass
if found:
print _("\tErrata Found!")
for f in found: print "\t%s" % f
else:
print _("\tNo errata found, if this machine is having issues please go to")
print _("\tyour profile and create a wiki page for the device so others can")
print _("\tbenefit")
示例4: ConnSetup
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import open [as 别名]
(opts, args) = parser.parse_args()
ConnSetup(opts.smoonURL, opts.user_agent, opts.timeout, None)
smolt.DEBUG = opts.DEBUG
smolt.hw_uuid_file = opts.uuidFile
# read the profile
profile = smolt.Hardware()
delHostString = 'uuid=%s' % profile.host.UUID
try:
req = Request('/client/delete')
req.add_header('Content-length', '%i' % len(delHostString))
req.add_header('Content-type', 'application/x-www-form-urlencoded')
req.add_data(delHostString)
o = req.open()
except urllib2.URLError, e:
sys.stderr.write(_('Error contacting Server:'))
sys.stderr.write(str(e))
sys.stderr.write('\n')
sys.exit(1)
else:
serverMessage(o.read())
o.close()
sys.stdout.write(_('Profile removed, please verify at'))
sys.stdout.write(' ')
sys.stdout.write(urljoin(opts.smoonURL + '/', '/client/show?%s\n' % delHostString))