Visitar URL original
Exception occurred: The request failed: Google returned a response with code 429. · Issue #561 · GeneralMills/pytrends · GitHub
Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Exception occurred: The request failed: Google returned a response with code 429.  #561

Closed

Description

Im getting the following error:

Exception occurred: The request failed: Google returned a response with code 429.

I think this could be because Google has a new trends website?

https://searchengineland.com/google-launches-new-google-trends-portal-394026

Is there a way to fix this issue? Thanks in advance

Activity

  1. Jinoy-Varghese commented on Mar 9, 2023

    @Jinoy-Varghese

    Even I'm also facing the same issue from 08/03/2023 : 5:00PM

  2. da2vin commented on Mar 9, 2023

    @da2vin

    Sam issue, who can tell me how to fix it?

  3. vimal-quilt commented on Mar 9, 2023

    @vimal-quilt

    Same Issue. when can this be fixed?

  4. da2vin commented on Mar 9, 2023

    @da2vin

    It seems to use grecapcha , for prevent crawling data...
    It's hard to resolve this problem

  5. Syndorik commented on Mar 9, 2023

    @Syndorik

    So I guess no easy work around this time?

  6. Syndorik commented on Mar 9, 2023

    @Syndorik

    Ok I might have found a work around. It appears that now, the first connection to google trends returns a 429, so if you setup the object with :
    pytrend = TrendReq(retries=3)

    It should work. I've tested it on my side and no more 429

  7. netvids commented on Mar 9, 2023

    @netvids

    I am still getting a 429 with retries=3. raise RetryError(e, request=request)
    requests.exceptions.RetryError: HTTPSConnectionPool(host='trends.google.com', port=443): Max retries exceeded with url: /trends/api/explore?hl=en-....Caused by ResponseError('too many 429 error responses'))

  8. nicktba commented on Mar 9, 2023

    @nicktba

    Ok I might have found a work around. It appears that now, the first connection to google trends returns a 429, so if you setup the object with : pytrend = TrendReq(retries=3)

    It should work. I've tested it on my side and no more 429

    Im getting

    HTTPSConnectionPool(host='trends.google.com', port=443): Max retries exceeded with URL: [URL] Caused by ResponseError('too many 429 error responses'))

  9. nicktba commented on Mar 9, 2023

    @nicktba

    I've heard that implementing cURL impersonate works to overcome the captcha issue

    Can someone try that and let us know?

  10. Jinoy-Varghese commented on Mar 9, 2023

    @Jinoy-Varghese

    Syndorik Brooo.... You are Insane. Really thankful to you man. I had to submit a project tomorrow based on this and now everything is working properly.

  11. nicktba commented on Mar 9, 2023

    @nicktba

    Wait, this worked for you? I'm still getting 429.

    Can you show your code?

  12. Jinoy-Varghese commented on Mar 9, 2023

    @Jinoy-Varghese

    pt = TrendReq(retries=3)
    pt.build_payload(terms)
    df = pt.interest_over_time()

    This works

  13. maxwnewcomer commented on Mar 9, 2023

    @maxwnewcomer

    Ok I might have found a work around. It appears that now, the first connection to google trends returns a 429, so if you setup the object with : pytrend = TrendReq(retries=3)

    It should work. I've tested it on my side and no more 429

    This didn't work for me.

    What I did find working (unsurprisingly, yet still possibly useful for some), is replacing the headers in the request_args with a valid cookie from browser.

    For those who need it working "now" (like Jinoy Varghese (@Jinoy-Varghese)) and the retries doesn't work, try inspecting element on the trends page, go to network, click on a ?geo request and copy the cookie into your construction of TrendReq.

    Should look like:

    p = TrendReq(request_args = {'headers': {'Cookie': NID COOKIE HERE}})

    Currently looking for a more consistent solution that isn't just spamming the google servers with more retries.

  14. nicktba commented on Mar 9, 2023

    @nicktba

    Ok I might have found a work around. It appears that now, the first connection to google trends returns a 429, so if you setup the object with : pytrend = TrendReq(retries=3)
    It should work. I've tested it on my side and no more 429

    This didn't work for me.

    What I did find working (unsurprisingly, yet still possibly useful for some), is replacing the headers in the request_args with a valid cookie from browser.

    For those who need it working "now" like Jinoy Varghese (@Jinoy-Varghese) and the retries dosn't work, try inspecting element on the trends page, go to network, click on a ?geo request and copy the cookie into your construction of TrendReq.

    Should look like:

    p = TrendReq(request_args = {'headers': {'Cookie': NID COOKIE HERE}})

    Isn't there a risk of running into issues doing this?

    borrowing cookies is not my preferred method

  15. maxwnewcomer commented on Mar 9, 2023

    @maxwnewcomer

    nicktba Yeah definitely not a long term solution. Just was saying in case someone needed a solution rn for a school project like Jinoy. Especially when there isn't a fix implemented yet.

  16. 28 remaining items

  17. tomfbush commented on Apr 6, 2023

    @tomfbush

    Daniel Y (@danielfree) this worked straight away for me, thanks! 👍

    Preceded with

    from selenium import webdriver
    import time
    

    to save people about 2 seconds 😄

  18. emlazzarin commented on Apr 8, 2023

    @emlazzarin
    Contributor

    I believe we resolved this with #570 which is now included in the v4.9.1 release. Thank you all for helping uncover the underlying issues!

  19. qcgm1978 commented on May 31, 2023

    @qcgm1978

    I believe I found a much simpler solution to Max Newcomer (@maxwnewcomer)'s. The request made in GetGoogleCookie is a GET, but it responds with a empty 200 response. But if you instead make do a POST, the API correctly responds with a cookie. The fix is simply to change this line to be requests.post.

    I would like to confirm that the proposed solution has worked for me perfectly. Thank you Max Newcomer (@maxwnewcomer)!

    Please see my comment if you need a temporary workaround to make your code work until the fix has been added to the library.

    I encountered this problem again. The version of pytrends is 4.9.2, but changing 'get' to 'post' in GetGoogleCookie function works.

  20. alaaddinsarac commented on Jul 12, 2023

    @alaaddinsarac

    I believe I found a much simpler solution to Max Newcomer (@maxwnewcomer)'s. The request made in GetGoogleCookie is a GET, but it responds with a empty 200 response. But if you instead make do a POST, the API correctly responds with a cookie. The fix is simply to change this line to be requests.post.

    thanks for the solution. I was going to lose my mind over this

  21. camirojasguajardo commented on Nov 24, 2023

    @camirojasguajardo

    I believe I found a much simpler solution to Max Newcomer (@maxwnewcomer)'s. The request made in GetGoogleCookie is a GET, but it responds with a empty 200 response. But if you instead make do a POST, the API correctly responds with a cookie. The fix is simply to change this line to be requests.post.

    Hi! does anyone know if this solution still works? im using pytrends 4.9.2

  22. AhmadKhanSenpai commented on Jan 8, 2024

    @AhmadKhanSenpai

    I believe I found a much simpler solution to Max Newcomer (@maxwnewcomer)'s. The request made in GetGoogleCookie is a GET, but it responds with a empty 200 response. But if you instead make do a POST, the API correctly responds with a cookie. The fix is simply to change this line to be requests.post.

    Hi! does anyone know if this solution still works? im using pytrends 4.9.2

    no it does not work, I was using it in my project and it was working fine but the next day its gives me the Too many Request error code 429

  23. Dojohn2004 commented on Jan 15, 2024

    @Dojohn2004

    I believe I found a much simpler solution to Max Newcomer (@maxwnewcomer)'s. The request made in GetGoogleCookie is a GET, but it responds with a empty 200 response. But if you instead make do a POST, the API correctly responds with a cookie. The fix is simply to change this line to be requests.post.

    Hi! does anyone know if this solution still works? im using pytrends 4.9.2

    no it does not work, I was using it in my project and it was working fine but the next day its gives me the Too many Request error code 429

    same here, it is not working for me.

  24. Dojohn2004 commented on Feb 29, 2024

    @Dojohn2004

    I believe I found a much simpler solution to Max Newcomer (@maxwnewcomer)'s. The request made in GetGoogleCookie is a GET, but it responds with a empty 200 response. But if you instead make do a POST, the API correctly responds with a cookie. The fix is simply to change this line to be requests.post.

    Hi! does anyone know if this solution still works? im using pytrends 4.9.2

    no it does not work, I was using it in my project and it was working fine but the next day its gives me the Too many Request error code 429

    same here, it is not working for me.

    I found it works sometimes, it works for few weeks ago, but now is not working again

  25. sumitsihag123 commented on Mar 18, 2024

    @sumitsihag123

    Hii, Google trend start blocking again. It is observed that this month we are not able to scrape data properly and it start working fine for 3-4 hours but again showing 429 error or malformed error.

  26. wheeler88 commented on Mar 19, 2024

    @wheeler88

    confirm its not working

  27. NathanBForBetter commented on Mar 19, 2024

    @NathanBForBetter

    Ditto. Not working for me either. Did curl method and nid method.

  28. interpner commented on Aug 6, 2024

    @interpner

    What is the current official fix?

  29. sumitsihag123 commented on Aug 6, 2024

    @sumitsihag123
  30. unytics commented on Feb 11, 2025

    @unytics

    I also got some 429 issues while building a bigquery function to help people load trends into bigquery.

    The only way I solved my problem was to implement nicktba suggestion: use cURL impersonate (to be honest it's not perfect but it's way better).

    I tried to patch pytrends but for some reasons, it failed. So, I started from scratch (with inspiration from this stackoverflow answer which caught my eye after nicktba comment)

    Here is:

    Besides, if some people here are on BigQuery, they can use this function for free by simply copy & pasting the function example in the documentation. No install is needed.

    (ping Max Newcomer (@maxwnewcomer) for info)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions