本文整理汇总了Python中urllib.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_control_image_path
def get_control_image_path(self, test_name):
if os.path.isfile(test_name):
return path
# else try and find matching test image
script_folder = os.path.dirname(os.path.realpath(sys.argv[0]))
control_images_folder = os.path.join(
script_folder, '../tests/testdata/control_images')
matching_control_images = [x[0]
for x in os.walk(control_images_folder) if test_name in x[0]]
if len(matching_control_images) > 1:
QMessageBox.warning(
self, 'Result', 'Found multiple matching control images for {}'.format(test_name))
return None
elif len(matching_control_images) == 0:
QMessageBox.warning(
self, 'Result', 'No matching control images found for {}'.format(test_name))
return None
found_control_image_path = matching_control_images[0]
# check for a single matching expected image
images = glob.glob(os.path.join(found_control_image_path, '*.png'))
filtered_images = [i for i in images if not i[-9:] == '_mask.png']
if len(filtered_images) > 1:
error(
'Found multiple matching control images for {}'.format(test_name))
elif len(filtered_images) == 0:
error('No matching control images found for {}'.format(test_name))
found_image = filtered_images[0]
print('Found matching control image: {}'.format(found_image))
return found_image
开发者ID:tomchadwin,项目名称:QGIS,代码行数:34,代码来源:parse_dash_results.py
示例2: upgrade
def upgrade(version):
"""
Upgrading program
:param version: version name for VK Stats
"""
log_write(_("Creating a temporary directory..."))
tmpdir = tempfile.mktemp(prefix="sysrq-")
os.mkdir(tmpdir)
log_write(_("Downloading the new version..."))
archive_file = "{}/VK_Stats.zip".format(tmpdir)
request.urlretrieve("https://github.com/CyberTailor/vk-stats/releases/download/{0}/Stats-{0}.zip".format(version),
filename=archive_file)
log_write(_("Unpacking an archive..."))
archive = zipfile.ZipFile(archive_file)
try:
archive.extractall(path=SCRIPTDIR) # extract ZIP to script directory
except PermissionError:
if console:
print(_("Please, upgrade the program using package manager or installer"))
exit()
else:
error(primary=_("Can't upgrade"),
secondary=_("Please, upgrade the program using package manager or installer"))
log_write(_("Exiting..."))
exit()
开发者ID:CyberTailor,项目名称:vk-stats,代码行数:25,代码来源:stats.py
示例3: initializeIceConnection
def initializeIceConnection(self):
"""
Establishes the two-way Ice connection and adds the authenticator to the
configured servers
"""
ice = self.communicator()
if cfg.ice.secret:
debug('Using shared ice secret')
ice.getImplicitContext().put("secret", cfg.ice.secret)
elif not cfg.glacier.enabled:
warning('Consider using an ice secret to improve security')
if cfg.glacier.enabled:
#info('Connecting to Glacier2 server (%s:%d)', glacier_host, glacier_port)
error('Glacier support not implemented yet')
#TODO: Implement this
info('Connecting to Ice server (%s:%d)', cfg.ice.host, cfg.ice.port)
base = ice.stringToProxy('Meta:tcp -h %s -p %d' % (cfg.ice.host, cfg.ice.port))
self.meta = Murmur.MetaPrx.uncheckedCast(base)
adapter = ice.createObjectAdapterWithEndpoints('Callback.Client', 'tcp -h %s' % cfg.ice.host)
adapter.activate()
metacbprx = adapter.addWithUUID(metaCallback(self))
self.metacb = Murmur.MetaCallbackPrx.uncheckedCast(metacbprx)
authprx = adapter.addWithUUID(DjangoAuthenticator())
self.auth = Murmur.ServerUpdatingAuthenticatorPrx.uncheckedCast(authprx)
return self.attachCallbacks()
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:32,代码来源:mumble-djangoauth.py
示例4: execute
def execute(cls, *args, **kwargs):
if "threadDB__retry_execution__" in kwargs:
# Have a magic keyword so we can call ourselves while preventing
# an infinite loopg
del kwargs["threadDB__retry_execution__"]
retry = False
else:
retry = True
c = cls.cursor()
try:
c.execute(*args, **kwargs)
except db.OperationalError as e:
error('Database operational error %d: %s', e.args[0], e.args[1])
c.close()
cls.invalidate_connection()
if retry:
# Make sure we only retry once
info('Retrying database operation')
kwargs["threadDB__retry_execution__"] = True
c = cls.execute(*args, **kwargs)
else:
error('Database operation failed ultimately')
raise threadDbException()
return c
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:25,代码来源:mumble-djangoauth.py
示例5: call_api
def call_api(method, *, token, params):
"""
Calling VK API
:param method: method name from https://vk.com/dev/methods
:param params: parameters for method (dict)
:param token: access_token
:return: result of calling API method
"""
params.update({"access_token": token, "v": api_ver})
data = urlencode(params)
headers = {"Content-length": str(len(data))}
url = "https://api.vk.com/method/" + method
req = request.Request(url, data=bytes(data, encoding="utf-8"), headers=headers)
result = None
while result is None:
try:
result = json.loads(request.urlopen(req, timeout=5).read().decode("utf-8"))
except (urllib.error.URLError, socket.error) as err:
log_write(_("Error: {}. Waiting for 10 seconds...").format(err))
time.sleep(10)
if "error" in result:
if console:
log_write("VK API {error_code}: {error_msg}".format(**result["error"]), to=sys.stderr)
exit()
else:
error(primary="VK API {error_code}".format(**result["error"]), secondary=result["error"]["error_msg"])
time.sleep(0.33)
return result["response"]
开发者ID:CyberTailor,项目名称:vk-stats,代码行数:29,代码来源:stats.py
示例6: get_configfiles
def get_configfiles(log):
''' Download lircd.conf and perhaps lircmd.conf, '''
def error(ex, uri):
''' Handle download error. '''
text = "Cannot download %s : %s" % (uri, str(ex))
view.show_error("Download error", text)
if 'lircd_conf' not in config or not config['lircd_conf'] \
or config['lircd_conf'] == _MANUAL_REMOTE_INSTALL:
# pylint: disable=bad-indentation
text = "No lircd.conf defined, skipping"
view.show_warning("Download error", text)
return log
for item in ['lircd_conf', 'lircmd_conf']:
if item not in config:
continue
uri = os.path.join(_REMOTES_BASE_URI, config[item])
path = os.path.join(result_dir, os.path.basename(config[item]))
try:
urllib.request.urlretrieve(uri + '?format=raw', path)
log += 'Info: Downloaded %s to %s\n' % (str(uri), str(path))
except urllib.error.HTTPError as ex:
error(ex, uri)
return log
开发者ID:JulianNymark,项目名称:blendergame,代码行数:25,代码来源:mvc_model.py
示例7: attachCallbacks
def attachCallbacks(self, quiet = False):
"""
Attaches all callbacks for meta and authenticators
"""
# Ice.ConnectionRefusedException
#debug('Attaching callbacks')
try:
if not quiet: info('Attaching meta callback')
self.meta.addCallback(self.metacb)
for server in self.meta.getBootedServers():
if not cfg.murmur.servers or server.id() in cfg.murmur.servers:
if not quiet: info('Setting authenticator for virtual server %d', server.id())
server.setAuthenticator(self.auth)
except (Murmur.InvalidSecretException, Ice.UnknownUserException, Ice.ConnectionRefusedException) as e:
if isinstance(e, Ice.ConnectionRefusedException):
error('Server refused connection')
elif isinstance(e, Murmur.InvalidSecretException) or \
isinstance(e, Ice.UnknownUserException) and (e.unknown == 'Murmur::InvalidSecretException'):
error('Invalid ice secret')
else:
# We do not actually want to handle this one, re-raise it
raise e
self.connected = False
return False
self.connected = True
return True
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:32,代码来源:mumble-djangoauth.py
示例8: get_configfiles
def get_configfiles(log):
''' Download lircd.conf and perhaps lircmd.conf, '''
def error(ex, uri):
''' Handle download error. '''
text = "Cannot download %s : %s" % (uri, str(ex))
view.show_error("Download error", text)
if not model.config.lircd_conf \
or model.config.lircd_conf == _MANUAL_REMOTE_INSTALL:
# pylint: disable=bad-indentation
text = "No lircd.conf defined, skipping"
view.show_warning("Download error", text)
return log
for item in ['lircd_conf', 'lircmd_conf']:
if not getattr(model.config, item):
continue
src = getattr(model.config, item)
if os.path.exists(src):
shutil.copy2(src, '.')
log += 'Info: Copied %s to %s\n' % (str(src), os.getcwd())
continue
uri = os.path.join(_REMOTES_BASE_URI, src)
path = os.path.join(result_dir, os.path.basename(src))
try:
urllib.request.urlretrieve(uri + '?format=raw', path)
log += 'Info: Downloaded %s to %s\n' % (str(uri), str(path))
except urllib.error.HTTPError as ex:
error(ex, uri)
return log
开发者ID:digideskio,项目名称:lirc,代码行数:30,代码来源:mvc_model.py
示例9: get_feed
def get_feed(url):
from meds.object import Object
import feedparser as fp
result = {}
try: data = get_url(url)
except Exception as ex: error("%s %s" % (url, get_exception())) ; return
result = fp.parse(data)
if "entries" in result:
for entry in result["entries"][::-1]: yield Object(entry)
开发者ID:bthate,项目名称:meds,代码行数:9,代码来源:misc.py
示例10: updateMask
def updateMask(control_image_path, rendered_image_path, mask_image_path):
control_image = imageFromPath(control_image_path)
if not control_image:
error("Could not read control image {}".format(control_image_path))
rendered_image = imageFromPath(rendered_image_path)
if not rendered_image:
error("Could not read rendered image {}".format(rendered_image_path))
if not rendered_image.width() == control_image.width() or not rendered_image.height() == control_image.height():
print(
(
"Size mismatch - control image is {}x{}, rendered image is {}x{}".format(
control_image.width(), control_image.height(), rendered_image.width(), rendered_image.height()
)
)
)
max_width = min(rendered_image.width(), control_image.width())
max_height = min(rendered_image.height(), control_image.height())
# read current mask, if it exist
mask_image = imageFromPath(mask_image_path)
if mask_image.isNull():
print("Mask image does not exist, creating {}".format(mask_image_path))
mask_image = QImage(control_image.width(), control_image.height(), QImage.Format_ARGB32)
mask_image.fill(QColor(0, 0, 0))
# loop through pixels in rendered image and compare
mismatch_count = 0
linebytes = max_width * 4
for y in range(max_height):
control_scanline = control_image.constScanLine(y).asstring(linebytes)
rendered_scanline = rendered_image.constScanLine(y).asstring(linebytes)
mask_scanline = mask_image.scanLine(y).asstring(linebytes)
for x in range(max_width):
currentTolerance = qRed(struct.unpack("I", mask_scanline[x * 4 : x * 4 + 4])[0])
if currentTolerance == 255:
# ignore pixel
continue
expected_rgb = struct.unpack("I", control_scanline[x * 4 : x * 4 + 4])[0]
rendered_rgb = struct.unpack("I", rendered_scanline[x * 4 : x * 4 + 4])[0]
difference = colorDiff(expected_rgb, rendered_rgb)
if difference > currentTolerance:
# update mask image
mask_image.setPixel(x, y, qRgb(difference, difference, difference))
mismatch_count += 1
if mismatch_count:
# update mask
mask_image.save(mask_image_path, "png")
print("Updated {} pixels in {}".format(mismatch_count, mask_image_path))
else:
print("No mismatches in {}".format(mask_image_path))
开发者ID:borysiasty,项目名称:QGIS,代码行数:57,代码来源:generate_test_mask_image.py
示例11: newfunc
def newfunc(*args, **kws):
if 'current' in kws:
current = kws["current"]
else:
current = args[-1]
if not current or 'secret' not in current.ctx or current.ctx['secret'] != cfg.ice.secret:
error('Server transmitted invalid secret. Possible injection attempt.')
raise Murmur.InvalidSecretException()
return func(*args, **kws)
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:11,代码来源:mumble-djangoauth.py
示例12: getControlImagePath
def getControlImagePath(path):
if os.path.isfile(path):
return path
# else try and find matching test image
script_folder = os.path.dirname(os.path.realpath(sys.argv[0]))
control_images_folder = os.path.join(script_folder, "../tests/testdata/control_images")
matching_control_images = [x[0] for x in os.walk(control_images_folder) if path in x[0]]
if len(matching_control_images) > 1:
error("Found multiple matching control images for {}".format(path))
elif len(matching_control_images) == 0:
error("No matching control images found for {}".format(path))
found_control_image_path = matching_control_images[0]
# check for a single matching expected image
images = glob.glob(os.path.join(found_control_image_path, "*.png"))
filtered_images = [i for i in images if not i[-9:] == "_mask.png"]
if len(filtered_images) > 1:
error("Found multiple matching control images for {}".format(path))
elif len(filtered_images) == 0:
error("No matching control images found for {}".format(path))
found_image = filtered_images[0]
print("Found matching control image: {}".format(found_image))
return found_image
开发者ID:borysiasty,项目名称:QGIS,代码行数:27,代码来源:generate_test_mask_image.py
示例13: __handle
def __handle(self, msg='', token=None, error=xml.dom.SyntaxErr,
neverraise=False, args=None):
"""
handles all calls
logs or raises exception
"""
if self.enabled:
if error is None:
error = xml.dom.SyntaxErr
line, col = None, None
if token:
if isinstance(token, tuple):
value, line, col = token[1], token[2], token[3]
else:
value, line, col = token.value, token.line, token.col
msg = '%s [%s:%s: %s]' % (
msg, line, col, value)
if error and self.raiseExceptions and not neverraise:
if isinstance(error, urllib.error.HTTPError) or isinstance(error, urllib.error.URLError):
raise
elif issubclass(error, xml.dom.DOMException):
error.line = line
error.col = col
raise error(msg)
else:
self._logcall(msg)
开发者ID:CudaText-addons,项目名称:cuda_css_prefixer,代码行数:28,代码来源:errorhandler.py
示例14: create_connection
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
"""Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional
*timeout* parameter will set the timeout on the socket instance
before attempting to connect. If no *timeout* is supplied, the
global default timeout setting returned by :func:`getdefaulttimeout`
is used. If *source_address* is set it must be a tuple of (host, port)
for the socket to bind as a source address before making the connection.
An host of '' or port 0 tells the OS to use the default.
"""
host, port = address
err = None
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket.socket(af, socktype, proto)
if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
if source_address:
sock.bind(source_address)
sock.connect(sa)
return sock
except error:
err = True
if sock is not None:
sock.close()
if err:
raise
else:
raise error("getaddrinfo returns an empty list")
开发者ID:geekman7473,项目名称:TwitterBotTest,代码行数:35,代码来源:ssl_support.py
示例15: started
def started(self, server, current = None):
"""
This function is called when a virtual server is started
and makes sure an authenticator gets attached if needed.
"""
if not cfg.murmur.servers or server.id() in cfg.murmur.servers:
info('Setting authenticator for virtual server %d', server.id())
try:
server.setAuthenticator(app.auth)
# Apparently this server was restarted without us noticing
except (Murmur.InvalidSecretException, Ice.UnknownUserException) as e:
if hasattr(e, "unknown") and e.unknown != "Murmur::InvalidSecretException":
# Special handling for Murmur 1.2.2 servers with invalid slice files
raise e
error('Invalid ice secret')
return
else:
debug('Virtual server %d got started', server.id())
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:19,代码来源:mumble-djangoauth.py
示例16: load_images
def load_images(self, control_image_path, rendered_image_path, mask_image_path):
self.control_image = imageFromPath(control_image_path)
if not self.control_image:
error('Could not read control image {}'.format(control_image_path))
self.rendered_image = imageFromPath(rendered_image_path)
if not self.rendered_image:
error(
'Could not read rendered image {}'.format(rendered_image_path))
if not self.rendered_image.width() == self.control_image.width() or not self.rendered_image.height() == self.control_image.height():
print(
'Size mismatch - control image is {}x{}, rendered image is {}x{}'.format(self.control_image.width(),
self.control_image.height(
),
self.rendered_image.width(
),
self.rendered_image.height()))
max_width = min(
self.rendered_image.width(), self.control_image.width())
max_height = min(
self.rendered_image.height(), self.control_image.height())
# read current mask, if it exist
self.mask_image = imageFromPath(mask_image_path)
if self.mask_image.isNull():
print(
'Mask image does not exist, creating {}'.format(mask_image_path))
self.mask_image = QImage(
self.control_image.width(), self.control_image.height(), QImage.Format_ARGB32)
self.mask_image.fill(QColor(0, 0, 0))
self.diff_image = self.create_diff_image(
self.control_image, self.rendered_image, self.mask_image)
if not self.diff_image:
self.load_next()
return
self.control_label.setPixmap(QPixmap.fromImage(self.control_image))
self.rendered_label.setPixmap(QPixmap.fromImage(self.rendered_image))
self.mask_label.setPixmap(QPixmap.fromImage(self.mask_image))
self.diff_label.setPixmap(QPixmap.fromImage(self.diff_image))
self.preview_mask()
开发者ID:tomchadwin,项目名称:QGIS,代码行数:43,代码来源:parse_dash_results.py
示例17: __data_parser__
def __data_parser__(self, data):
try:
if data['mods']['itemlist']['data']['auctions']:
search_results = data['mods']['itemlist']['data']['auctions']
return [{
'intro': result["raw_title"],
'price': float(result["view_price"]),
'delivery': colorful_text(result["view_fee"], Fore.RED)
if float(result["view_fee"]) > 0 else result["view_fee"],
'sales': int(result["view_sales"].split('人')[0]),
'belong': colorful_text("天猫", Fore.CYAN)
if result.get('shopcard', {}).get('isTmall', False) else "淘宝",
'url': result["detail_url"]
} for result in search_results]
error('Ops, get no goods..')
return []
except KeyError:
error('Ops, some key error happened..')
return []
开发者ID:ecmadao,项目名称:Hands-Chopping,代码行数:19,代码来源:spider_taobao.py
示例18: checkConnection
def checkConnection(self):
"""
Tries reapplies all callbacks to make sure the authenticator
survives server restarts and disconnects.
"""
#debug('Watchdog run')
try:
if not self.attachCallbacks(quiet = not self.failedWatch):
self.failedWatch = True
else:
self.failedWatch = False
except Ice.Exception as e:
error('Failed connection check, will retry in next watchdog run (%ds)', cfg.ice.watchdog)
debug(str(e))
self.failedWatch = True
# Renew the timer
self.watchdog = Timer(cfg.ice.watchdog, self.checkConnection)
self.watchdog.start()
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:20,代码来源:mumble-djangoauth.py
示例19: connection
def connection(cls):
tid = _thread.get_ident()
try:
con = cls.db_connections[tid]
except:
info('Connecting to database server (%s %s:%d %s) for thread %d',
cfg.database.lib, cfg.database.host, cfg.database.port, cfg.database.name, tid)
try:
con = db.connect(host = cfg.database.host,
port = cfg.database.port,
user = cfg.database.user,
password = cfg.database.password,
database = cfg.database.name)
con.autocommit = True
except db.Error as e:
error('Could not connect to database: %s', str(e))
raise threadDbException()
cls.db_connections[tid] = con
return con
开发者ID:fsinfuhh,项目名称:mafiasi,代码行数:22,代码来源:mumble-djangoauth.py
示例20: main
def main():
p = args_parser('download recent puzzles')
args = get_args(parser=p)
outf = open_output()
today = datetime.date.today()
todaystr = today.strftime("%Y-%m-%d")
sources_tsv = ''
puzzle_sources = xd_puzzle_sources()
new_recents_tsv = []
# some downloads may fail, track the last successful ones
most_recent = {}
# download new puzzles since most recent download
for row in metadb.xd_recent_downloads().values():
pubid = row.pubid
latest_date = datestr_to_datetime(row.date)
# by default, keep the previous one
most_recent[pubid] = row.date
if pubid not in puzzle_sources:
warn("unknown puzzle source for '%s', skipping" % pubid)
continue
puzsrc = puzzle_sources[pubid]
if not puzsrc.urlfmt or puzsrc.urlfmt.startswith("#"):
warn("no source url for '%s', skipping" % pubid)
continue
from_date = latest_date
to_date = today
dates_to_get = get_dates_between(from_date, to_date, int(puzsrc.freq))
if not dates_to_get:
warn("*** %s: nothing to get since %s" % (pubid, from_date))
continue
summary("*** %s: downloading %d puzzles from %s to %s" % (pubid, len(dates_to_get), from_date, to_date))
for dt in sorted(dates_to_get):
try:
xdid = construct_xdid(pubid, dt)
url = dt.strftime(puzsrc.urlfmt)
fn = "%s.%s" % (xdid, puzsrc.ext)
debug("downloading '%s' from '%s'" % (fn, url))
response = urllib.request.urlopen(url)
content = response.read()
outf.write_file(fn, content)
most_recent[pubid] = todaystr
except (urllib.error.HTTPError, urllib.error.URLError) as err:
error('%s [%s] %s: %s' % (xdid, err.code, err.reason, url))
except Exception as e:
error(str(e))
sources_tsv += xd_sources_row(fn, url, todaystr)
for k, v in most_recent.items():
new_recents_tsv.append(xd_recent_download(k, v))
if sources_tsv:
outf.write_file("sources.tsv", xd_sources_header + sources_tsv)
if new_recents_tsv:
# on filesystem
open(metadb.RECENT_DOWNLOADS_TSV, "w").write(xd_recents_header + "".join(sorted(new_recents_tsv)))
开发者ID:century-arcade,项目名称:xd,代码行数:75,代码来源:11-download-puzzles.py
注:本文中的urllib.error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论