本文整理汇总了Python中qgis.server.QgsServerResponse.setStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Python QgsServerResponse.setStatusCode方法的具体用法?Python QgsServerResponse.setStatusCode怎么用?Python QgsServerResponse.setStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.server.QgsServerResponse
的用法示例。
在下文中一共展示了QgsServerResponse.setStatusCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pdf
# 需要导入模块: from qgis.server import QgsServerResponse [as 别名]
# 或者: from qgis.server.QgsServerResponse import setStatusCode [as 别名]
def get_pdf(self, params: Dict[str,str], response: QgsServerResponse ) -> None:
""" Get PDF files previously exported
"""
ptoken = params.get('TOKEN')
if not ptoken:
raise CadastreError(400,"Missing parameter: token")
path = self.cachedir / ('%s.pdf' % ptoken)
if self.debugMode:
QgsMessageLog.logMessage("GetPDF = path is %s" % path.as_posix(),'cadastre', Qgis.Debug)
if not path.exists():
raise CadastreError(404,"PDF not found")
# Send PDF
response.setHeader('Content-type', 'application/pdf')
response.setStatusCode(200)
try:
response.write(path.read_bytes())
path.unlink()
except:
QgsMessageLog.logMessage("Error occured while reading PDF file",'cadastre',QGis.Critical)
raise
示例2: write_json_response
# 需要导入模块: from qgis.server import QgsServerResponse [as 别名]
# 或者: from qgis.server.QgsServerResponse import setStatusCode [as 别名]
def write_json_response( data: Dict[str,str], response: QgsServerResponse, code: int=200) -> None:
""" Write data as json response
"""
response.setStatusCode(code)
response.setHeader("Content-Type", "application/json")
response.write(json.dumps(data))