Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python计划:缺少1个必需的位置参数?_Python_Python 3.x_Scheduled Tasks_Schedule - Fatal编程技术网

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'”。我试图将其传递到schedule
schedule.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)