PyTrends Keeps returning Google Response with error code 400












0















I've been trying to pull google trends data for a number of different keywords and have been looping over each keyword using pandas to build each individual payload. However, I keep getting a Google error code of 400 when I try using a particular row of the keyword. This is the code that I have currently



import csv
import time
import pandas as pd
from random import randint
from pytrends.request import TrendReq

# set gmail credentials and path to extract data


# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()
keywordcsv = "nba.csv"
keywords = pd.read_csv(keywordcsv)
print(keywords)
for index, row in keywords.iterrows():
print("Downloading Keyword #" + str(index))
temp = str(row[0])
pytrend.build_payload(kw_list=temp, timeframe="2013-11-24 2018-11-11", geo='US')
time.sleep(randint(5, 10))
null_df = pytrend.interest_over_time()
print(null_df)
null_df.to_csv(path_or_buf='blah.csv', mode='a', header=0)


Any help is greatly appreciated!










share|improve this question























  • Which keyword is causing the error??

    – Peter Leimbigler
    Nov 24 '18 at 23:48











  • whenever I use a variable for a keyword like temp or row[0], it gives me the 400 error. However, if I explicitly put the keyword such as kw_list = ["wizards"] then it works fine. I want to dynamically keep building different payloads based on the csv file.

    – Advait Kulkarni
    Nov 25 '18 at 17:32











  • Actually, I just checked. When I declare temp = "wizards" and then pass in [temp] into the kw_list, it seems to work. However, whenever I try to do temp = row[0], it doesn't work and returns an empty data frame.

    – Advait Kulkarni
    Nov 25 '18 at 17:46











  • @PeterLeimbigler

    – Advait Kulkarni
    Nov 25 '18 at 18:46











  • Add print(row[0]) to your loop and see what it is trying to pass in as a keyword. Also, could you post the result of print(keywords)?

    – Peter Leimbigler
    Nov 25 '18 at 20:28
















0















I've been trying to pull google trends data for a number of different keywords and have been looping over each keyword using pandas to build each individual payload. However, I keep getting a Google error code of 400 when I try using a particular row of the keyword. This is the code that I have currently



import csv
import time
import pandas as pd
from random import randint
from pytrends.request import TrendReq

# set gmail credentials and path to extract data


# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()
keywordcsv = "nba.csv"
keywords = pd.read_csv(keywordcsv)
print(keywords)
for index, row in keywords.iterrows():
print("Downloading Keyword #" + str(index))
temp = str(row[0])
pytrend.build_payload(kw_list=temp, timeframe="2013-11-24 2018-11-11", geo='US')
time.sleep(randint(5, 10))
null_df = pytrend.interest_over_time()
print(null_df)
null_df.to_csv(path_or_buf='blah.csv', mode='a', header=0)


Any help is greatly appreciated!










share|improve this question























  • Which keyword is causing the error??

    – Peter Leimbigler
    Nov 24 '18 at 23:48











  • whenever I use a variable for a keyword like temp or row[0], it gives me the 400 error. However, if I explicitly put the keyword such as kw_list = ["wizards"] then it works fine. I want to dynamically keep building different payloads based on the csv file.

    – Advait Kulkarni
    Nov 25 '18 at 17:32











  • Actually, I just checked. When I declare temp = "wizards" and then pass in [temp] into the kw_list, it seems to work. However, whenever I try to do temp = row[0], it doesn't work and returns an empty data frame.

    – Advait Kulkarni
    Nov 25 '18 at 17:46











  • @PeterLeimbigler

    – Advait Kulkarni
    Nov 25 '18 at 18:46











  • Add print(row[0]) to your loop and see what it is trying to pass in as a keyword. Also, could you post the result of print(keywords)?

    – Peter Leimbigler
    Nov 25 '18 at 20:28














0












0








0








I've been trying to pull google trends data for a number of different keywords and have been looping over each keyword using pandas to build each individual payload. However, I keep getting a Google error code of 400 when I try using a particular row of the keyword. This is the code that I have currently



import csv
import time
import pandas as pd
from random import randint
from pytrends.request import TrendReq

# set gmail credentials and path to extract data


# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()
keywordcsv = "nba.csv"
keywords = pd.read_csv(keywordcsv)
print(keywords)
for index, row in keywords.iterrows():
print("Downloading Keyword #" + str(index))
temp = str(row[0])
pytrend.build_payload(kw_list=temp, timeframe="2013-11-24 2018-11-11", geo='US')
time.sleep(randint(5, 10))
null_df = pytrend.interest_over_time()
print(null_df)
null_df.to_csv(path_or_buf='blah.csv', mode='a', header=0)


Any help is greatly appreciated!










share|improve this question














I've been trying to pull google trends data for a number of different keywords and have been looping over each keyword using pandas to build each individual payload. However, I keep getting a Google error code of 400 when I try using a particular row of the keyword. This is the code that I have currently



import csv
import time
import pandas as pd
from random import randint
from pytrends.request import TrendReq

# set gmail credentials and path to extract data


# Login to Google. Only need to run this once, the rest of requests will use the same session.
pytrend = TrendReq()
keywordcsv = "nba.csv"
keywords = pd.read_csv(keywordcsv)
print(keywords)
for index, row in keywords.iterrows():
print("Downloading Keyword #" + str(index))
temp = str(row[0])
pytrend.build_payload(kw_list=temp, timeframe="2013-11-24 2018-11-11", geo='US')
time.sleep(randint(5, 10))
null_df = pytrend.interest_over_time()
print(null_df)
null_df.to_csv(path_or_buf='blah.csv', mode='a', header=0)


Any help is greatly appreciated!







python-3.x pandas google-trends






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 21:37









Advait KulkarniAdvait Kulkarni

63




63













  • Which keyword is causing the error??

    – Peter Leimbigler
    Nov 24 '18 at 23:48











  • whenever I use a variable for a keyword like temp or row[0], it gives me the 400 error. However, if I explicitly put the keyword such as kw_list = ["wizards"] then it works fine. I want to dynamically keep building different payloads based on the csv file.

    – Advait Kulkarni
    Nov 25 '18 at 17:32











  • Actually, I just checked. When I declare temp = "wizards" and then pass in [temp] into the kw_list, it seems to work. However, whenever I try to do temp = row[0], it doesn't work and returns an empty data frame.

    – Advait Kulkarni
    Nov 25 '18 at 17:46











  • @PeterLeimbigler

    – Advait Kulkarni
    Nov 25 '18 at 18:46











  • Add print(row[0]) to your loop and see what it is trying to pass in as a keyword. Also, could you post the result of print(keywords)?

    – Peter Leimbigler
    Nov 25 '18 at 20:28



















  • Which keyword is causing the error??

    – Peter Leimbigler
    Nov 24 '18 at 23:48











  • whenever I use a variable for a keyword like temp or row[0], it gives me the 400 error. However, if I explicitly put the keyword such as kw_list = ["wizards"] then it works fine. I want to dynamically keep building different payloads based on the csv file.

    – Advait Kulkarni
    Nov 25 '18 at 17:32











  • Actually, I just checked. When I declare temp = "wizards" and then pass in [temp] into the kw_list, it seems to work. However, whenever I try to do temp = row[0], it doesn't work and returns an empty data frame.

    – Advait Kulkarni
    Nov 25 '18 at 17:46











  • @PeterLeimbigler

    – Advait Kulkarni
    Nov 25 '18 at 18:46











  • Add print(row[0]) to your loop and see what it is trying to pass in as a keyword. Also, could you post the result of print(keywords)?

    – Peter Leimbigler
    Nov 25 '18 at 20:28

















Which keyword is causing the error??

– Peter Leimbigler
Nov 24 '18 at 23:48





Which keyword is causing the error??

– Peter Leimbigler
Nov 24 '18 at 23:48













whenever I use a variable for a keyword like temp or row[0], it gives me the 400 error. However, if I explicitly put the keyword such as kw_list = ["wizards"] then it works fine. I want to dynamically keep building different payloads based on the csv file.

– Advait Kulkarni
Nov 25 '18 at 17:32





whenever I use a variable for a keyword like temp or row[0], it gives me the 400 error. However, if I explicitly put the keyword such as kw_list = ["wizards"] then it works fine. I want to dynamically keep building different payloads based on the csv file.

– Advait Kulkarni
Nov 25 '18 at 17:32













Actually, I just checked. When I declare temp = "wizards" and then pass in [temp] into the kw_list, it seems to work. However, whenever I try to do temp = row[0], it doesn't work and returns an empty data frame.

– Advait Kulkarni
Nov 25 '18 at 17:46





Actually, I just checked. When I declare temp = "wizards" and then pass in [temp] into the kw_list, it seems to work. However, whenever I try to do temp = row[0], it doesn't work and returns an empty data frame.

– Advait Kulkarni
Nov 25 '18 at 17:46













@PeterLeimbigler

– Advait Kulkarni
Nov 25 '18 at 18:46





@PeterLeimbigler

– Advait Kulkarni
Nov 25 '18 at 18:46













Add print(row[0]) to your loop and see what it is trying to pass in as a keyword. Also, could you post the result of print(keywords)?

– Peter Leimbigler
Nov 25 '18 at 20:28





Add print(row[0]) to your loop and see what it is trying to pass in as a keyword. Also, could you post the result of print(keywords)?

– Peter Leimbigler
Nov 25 '18 at 20:28












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462586%2fpytrends-keeps-returning-google-response-with-error-code-400%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462586%2fpytrends-keeps-returning-google-response-with-error-code-400%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'