Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPError: Bad response when making requests in loop #19

Open
JoBerkner opened this issue Nov 15, 2019 · 1 comment
Open

HTTPError: Bad response when making requests in loop #19

JoBerkner opened this issue Nov 15, 2019 · 1 comment
Assignees

Comments

@JoBerkner
Copy link

JoBerkner commented Nov 15, 2019

I am getting a

HTTPError: Bad response

I was so free to actually get the correct error code. It is a 400 bad request code.

It seems it only happens when I use a loop through my pandas dataframe instances because when I run my code for a single instance I am getting the correct values as well as when I am using a direct URL request in my browser.

Here is my function which is called later (with df being the dataframe)

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 asssign with location data
    key = 'MYKEY'
    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
@lukaskubis
Copy link
Owner

How many of these requests are you making? Keep in mind that your API key will allow you to do max 1000 requests per day.

@lukaskubis lukaskubis self-assigned this Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants