在Python中使用darkskylib库时出现错误请求

在Python中使用darkskylib库时出现错误请求,python,http-error,darksky,Python,Http Error,Darksky,我得到一份工作 HTTPError:错误响应 尝试使用Python中的darkskylib接收黑暗天空API的天气数据时。实际上,这是一个400错误的请求代码 似乎只有当我在pandas dataframe实例中使用循环时才会发生这种情况,因为当我为单个实例运行代码时,以及在浏览器中使用直接URL请求时,都会得到正确的值 这是我稍后调用的函数(数据帧为df) 我的特别问题是,我将datetime转换为date。因此,与其写作 t=row[“TIMESTAMP”].date().isoformat

我得到一份工作

HTTPError:错误响应

尝试使用Python中的darkskylib接收黑暗天空API的天气数据时。实际上,这是一个400错误的请求代码

似乎只有当我在pandas dataframe实例中使用循环时才会发生这种情况,因为当我为单个实例运行代码时,以及在浏览器中使用直接URL请求时,都会得到正确的值

这是我稍后调用的函数(数据帧为
df


我的特别问题是,我将
datetime
转换为
date
。因此,与其写作

t=row[“TIMESTAMP”].date().isoformat()

我需要写信

t=row[“TIMESTAMP”].isoformat()

def engineer_features(df):
    from datetime import datetime as dt
    from darksky import forecast

    print("Add weather data...")

    # Add Windspeed
    df['ISSTORM'] = 0

    # Add Temperature
    df['ISHOT'] = 0
    df['ISCOLD'] = 0

    # Add Precipitation probability 
    #    (because the weather station is not at the coordinate of the taxi 
    #    only a probability is added, but in regard to the center of Porto 
    #    (because else the API calls would have been costly))
    df['PRECIPPROB'] = 0

    # sort data frame
    data_times = df.sort_values(by='TIMESTAMP')

    # initialize variable for previous day's date day (day before the first day)
    prevDay = data_times.at[0,'TIMESTAMP'].date().day - 1

    #initialize hour counter
    hourCount = 0

    # add personal DarkSky API key and assign with location data
    key = 'MY_API_KEY'
    PORTO = key, 41.1579, -8.6291

    # loop through the sorted dataframe and add weather related data to the main dataframe
    for index, row in data_times.iterrows():

        # if the new row is a new day make a new API call for weather data of that new day
        if row["TIMESTAMP"].day != prevDay:

            # get Weather data
            t = row["TIMESTAMP"].date().isoformat()
            porto = forecast(*PORTO, time=t)
            porto.refresh(units='si')

        ###...more code