skip to Main Content

I am using Yahoo Finance’s API at https://query1.finance.yahoo.com/v8/finance/chart/Ticker with php’s file_get_contents and getting "failed to open stream: HTTP request failed! HTTP/1.0 429 Too Many Requests" but when I use curl to the same URL from the command line of the server I get an actual response! I verified that both of the requests are coming from the same IP.

I am not sending many requests – I sent maybe 40 get requests last night and then my first request today failed. My question is – has anyone seen the same type of problem? I read that the limit was 100 requests per hour – which I was well under!

Any advice would be appreciated.

2

Answers


  1. Since you noticed that curl works, try adding a user agent to your request to mimic curl.

    <?php
    
    $url = "https://query1.finance.yahoo.com/v8/finance/chart/nvda"; 
    
    $options = [
        'http' => [
            'method' => "GET",
            'header' => "User-Agent: curl/7.68.0rn"
        ]
    ];
    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    
    if ($response !== false) {
        echo "Response: " . $response;
    } else {
        echo "Request failed";
    }
    
    ?>
    

    I was running into the same issue in Rust and adding a similar user-agent to the request fixed it. You can also try a browser user agent such as Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36.

    Login or Signup to reply.
  2. I have the same issue today with yahoo, but I get similar when I’m just browsing GitHub.

    On GitHub:

    Whoa there! You have exceeded a secondary rate limit.

    Please wait a few minutes before you try again; in some cases this may
    take up to an hour.

    On Yahoo:

    Call failed with status code 429 (Too Many Requests): GET
    https://query1.finance.yahoo.com/v8/finance/quote?symbols=EURILS%3DX&crumb=SryHRDouZx7

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search