我需要你的建议。我建立与WMS(Web地图服务)的连接。如果连接已经建立,WMS添加在matplot窗口中绘制。在大多数情况下,正确地显示从WMS图像。但是,也有(我附后)当从WMS加载图像太长,这会导致错误的情况。这通常是超时错误。
我想带我的代码中,在当超过超时时刻从WMS图像停止加载形式。我想避免图像再次请求。
为此,我想除了TimeError。不幸的是,我不能。当然,我试过
除了:
方法(没有指定错误),但它不工作。下面的代码也不起作用。
try:
resp = requests.get('http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer')
odpowiedz_wms = resp.status_code except:
resp.status_code = 0 if resp.status_code == 200:
wms = ax.add_wms(wms='http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer', layers=['Raster'])
try:
plt.draw()
except (requests.exceptions.RequestException,socket.timeout,timeout, exceptions.ConnectionError,ReadTimeout, TimeoutError, exceptions.Timeout,exceptions.ReadTimeoutError,ReadTimeoutError,exceptions.ConnectTimeout, exceptions.ReadTimeout, requests.exceptions.ReadTimeout, urllib3.exceptions.ReadTimeoutError, socket.timeout) as e:
wms.remove()
plt.draw()
例外的Tkinter回调回溯(最近通话最后一个):(...)
文件 “C:\ Python35 \ LIB \ socket.py”,线路575,在readinto回报self._sock.recv_into(B)socket.timeout:超时
在处理上述异常,另一个异常:
回溯(最近通话最后一个):(......)文件 “C:\站点包\ urllib3 \ connectionpool.py Python35 \ LIB \”,线路306,在_raise_timeout提高ReadTimeoutError(自我,网址,“读超时。 (读取超时=%S)”%timeout_value)urllib3.exceptions.ReadTimeoutError:HTTPConnectionPool(主机= 'mapy.geoportal.gov.pl',端口= 80):读超时。 (读取超时= 30)
在处理上述异常,另一个异常:
回溯(最近通话最后一个):(......)R = adapter.send(请求,** kwargs)文件 “C:\ Python35 \ LIB \站点包\请求\ adapters.py”,线路526,在发送提高ReadTimeout(即,请求=请求)requests.exceptions.ReadTimeout:HTTPConnectionPool(主机= 'mapy.geoportal.gov.pl',端口= 80):读超时。 (读取超时= 30)
当一个异常中的一段代码抛出
try:
try:
1/0
except ZeroDivisionError:
# Catches the ZeroDivisionError
raise IndexError
except IndexError:
# Catches the IndexError - Doesn't need to catch the ZeroDivisionError
raise NameError # raises unhandled exception. Process terminated and entire stack trace will be printed
Traceback (most recent call last):
File "pyex.py", line 14, in <module>
1/0
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pyex.py", line 17, in <module>
raise IndexError
IndexError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pyex.py", line 21, in <module>
raise NameError # raises unhandled exception. Entire stack trace
will be printed out
NameError