Python计划:缺少1个必需的位置参数?
这是我的密码Python计划:缺少1个必需的位置参数?,python,python-3.x,scheduled-tasks,schedule,Python,Python 3.x,Scheduled Tasks,Schedule,这是我的密码 from API.helpers import get_weather_data, json_to_df, create_dict import schedule, time URL = 'https://pm1aapplicantsdata.blob.core.windows.net/databases/CitiesWeather/CitiesWeather.csv' columns = ["name","sys.country","main.temp",
from API.helpers import get_weather_data, json_to_df, create_dict
import schedule, time
URL = 'https://pm1aapplicantsdata.blob.core.windows.net/databases/CitiesWeather/CitiesWeather.csv'
columns = ["name","sys.country","main.temp",
"main.humidity","main.pressure",
"visibility", "wind.speed"]
def weather_api(URL):
dict = create_dict(URL)
for city, code in dict.items():
data = get_weather_data(city, code)
json_to_df(data, columns)
schedule.every(10).minutes.do(weather_api())
while True:
schedule.run_pending()
time.sleep(1)
我想做的是定期运行它。但是,我得到一个错误,说“weather_api()缺少1个必需的位置参数:'URL'”。我试图将其传递到scheduleschedule.every(10).minutes.do(weather_api(URL))
中,但随后我得到了第一个参数必须是可调用的
错误。同样在这种情况下
def weather_api():
URL = 'https://pm1aapplicantsdata.blob.core.windows.net/databases/CitiesWeather/CitiesWeather.csv'
dict = create_dict(URL)
for city, code in dict.items():
data = get_weather_data(city, code)
json_to_df(data, columns)
schedule.every(10).minutes.do(weather_api())
while True:
schedule.run_pending()
time.sleep(1)
…错误仍然存在。我以前尝试过使用高级Python调度程序,但问题是相同的。否则我的剧本就很好了。我做错了什么
提前非常感谢我不确定如何在
.do()
中发送参数,但是关于第二个异常,您应该这样运行它:
schedule.every(10).minutes.do(weather_api)
而不是weather\u api()
.do()
需要一个函数作为参数,而weather\u api
是您需要发送的函数,而不是它返回的数据(通过向其中添加()
)
我希望我写得足够清楚。:) 见
您可能需要使用schedule.every(10).minutes.do(天气api,URL)