【发布时间】:2021-04-26 17:35:58
【问题描述】:
我有下面的python 代码使用flask 和request:
from flask import request
@app.route('/v1/api/check_current_weather_by_city?city=Tel-aviv')
def check_current_weather_by_city():
city = request.args.get('city')
但是 city 没有得到 Tel-aviv 的期望值,但是抛出异常:
_lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.
我正在使用这项服务: https://openweathermap.org/current
【问题讨论】:
-
@app.route('/v1/api/check_current_weather_by_city') -
从规则定义中删除
?city=Tel-aviv部分。那是请求可能给出的。你怎么称呼它? -
根据服务的文档,调用是:
api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key}