GeneralMills / pytrends

Pseudo API for Google Trends
Other
3.28k stars 821 forks source link

pytrend.trend problem #65

Closed abutremutante closed 8 years ago

abutremutante commented 8 years ago

I'm adapting my application to your new code. I'm using the following code:

# connect to Google
pytrend = TrendReq(google_username, google_password, custom_useragent='Hey!')

# make request

def google_request():
    googlekey="tomate"
    search_param={'q':googlekey,'h1':'pt-BR','geo':'BR'}
    trend=pytrend.trend(search_param,return_type='dataframe')

Apparently there is a problem here trend=pytrend.trend(search_param,return_type='dataframe')

As you can see in the below traceback:

Traceback (most recent call last):
Response did not parse. See server response for details.
This page is currently unavailable. Please try again later.<br/> Please make sure your query is valid and try again.<br/> If you're experiencing long delays, consider reducing your comparison items.<br/> Thanks for your patience.

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pytrends/request.py", line 79, in trend

self.results = json.loads(text)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/santanna_santanna/PycharmProjects/Predictive Models/APIGtrends.py", line 37, in <module>
google_request()
File "/Users/santanna_santanna/PycharmProjects/Predictive Models/APIGtrends.py", line 27, in google_request
trend=pytrend.trend(search_param,return_type='dataframe')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pytrends/request.py", line 81, in trend
raise ResponseError(req.content)
pytrends.request.ResponseError: b'<!DOCTYPE html><html ><head><meta name="google-site-verification" content="-uo2JByp3-hxDA1ZgvM3dP8BE1_qDDddCm_st_w41P8" /><meta...
[ HERE COMES A LONG LONG LONG HTML CODE] ...This page is currently unavailable. Please try again later.&lt;br/&gt; Please make sure your query is valid and try again.&lt;br/&gt; If you&#39;re experiencing long delays, consider reducing your comparison items.&lt;br/&gt; Thanks for your patience.</div></div></div></div></div></div></div></div><div class="gb_6a"></div></body></html>'

Any ideas where might be the prob?

dreyco676 commented 8 years ago

I think you have h1 instead of hl. The third line states there is an issue with your request to Google.

dreyco676 commented 8 years ago

To be clear one is a number the other is the letter 'L'

abutremutante commented 8 years ago

That was indeed correct, however even correcting it the problem keeps happening.

dreyco676 commented 8 years ago

Do you get the same error or is it different?

abutremutante commented 8 years ago

Same one but with a portuguese message now (it was able to check my language since now I'm using "hl") - it says something like "Our servers are overloaded, try again later". Maybe I should wait a bit before trying again. I will let you know if that worked.

Response did not parse. See server response for details.
Nossos sistemas estão sobrecarregados no momento e precisam de alguns minutos para voltar ao normal. Tente novamente em alguns instantes.

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pytrends/request.py", line 79, in trend
self.results = json.loads(text)

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads

return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/santanna_santanna/PycharmProjects/Predictive Models/APIGtrends.py", line 36, in <module>
google_request()
File "/Users/santanna_santanna/PycharmProjects/Predictive Models/APIGtrends.py", line 26, in google_request
trend=pytrend.trend(search_param,return_type='dataframe')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pytrends/request.py", line 81, in trend
raise ResponseError(req.content)
pytrends.request.ResponseError: b'<!DOCTYPE html><html ><head>....[LONG LONG HTML CODE] 
abutremutante commented 8 years ago

Worked. Problem solved. Trying to solve a new one now. Thanks again.

jblemoine commented 7 years ago

@abutremutante I am facing the same issue when requesting from Google, whereas it was working a couple of months ago :

Response did not parse. See server response for details. This page is currently unavailable. Please try again later.Please make sure your query is valid and try again.If you're experiencing long delays, consider reducing your comparison items.Thanks for your patience.

How did you manage to solve this problem exactly? This seems to be due to overcharged servers at Google. Did you just spaced out your request with time.sleep() ?

Thanks for your help.