1

This question already has an answer here:

I'm working on an app that makes a request to the SE API over HTTP. The app works fine until the 300th request.
I requested/received an API key, but once I append it to the URL, I start receiving errors.

[(u'error_id', 400), (u'error_message', u'fromdate'), (u'error_name', u'bad_parameter')]

It appears to be telling me the fromdate parameter is invalid, but the query works fine until I add the key.

What am I doing wrong here?

Code as requested:

import urllib
import json
from datetime import date,timedelta
from time import sleep
import zlib

burl = 'https://api.stackexchange.com/2.2/search/advanced?&'
apiKey = "$KEY_VALUE"
langList = ['python', 'r', 'SAS']

for lang in langList:
    #paramsList = [('fromdate', "2017-02-15"), ('todate', "2017-02-16"), ('order', 'desc'), ('tagged', lang), ('sort', 'activity'), ('site', 'stackoverflow'), ('filter', 'total'), ('key', apiKey)]
    paramsList = [('fromdate', "2017-02-15"), ('todate', "2017-02-16"), ('order', 'desc'), ('tagged', lang), ('sort', 'activity'), ('site', 'stackoverflow'), ('filter', 'total')]
    dailyUrl = burl + urllib.urlencode(paramsList)
    print dailyUrl
    dailyRes =  json.loads(zlib.decompress(urllib.urlopen(dailyUrl).read(), 15 + 32))
    print dailyRes.items()

The results are either:

https://api.stackexchange.com/2.2/search/advanced?&fromdate=2017-02-15&todate=2017-02-16&order=desc&tagged=python&sort=activity&site=stackoverflow&filter=total
[(u'total', 690)]
https://api.stackexchange.com/2.2/search/advanced?&fromdate=2017-02-15&todate=2017-02-16&order=desc&tagged=r&sort=activity&site=stackoverflow&filter=total
[(u'total', 227)]
https://api.stackexchange.com/2.2/search/advanced?&fromdate=2017-02-15&todate=2017-02-16&order=desc&tagged=SAS&sort=activity&site=stackoverflow&filter=total
[(u'total', 10)]

or

https://api.stackexchange.com/2.2/search/advanced?&fromdate=2017-02-15&todate=2017-02-16&order=desc&tagged=python&sort=activity&site=stackoverflow&filter=total&key=$KEY_VALUE
[(u'error_id', 400), (u'error_message', u'fromdate'), (u'error_name', u'bad_parameter')]
https://api.stackexchange.com/2.2/search/advanced?&fromdate=2017-02-15&todate=2017-02-16&order=desc&tagged=r&sort=activity&site=stackoverflow&filter=total&key=$KEY_VALUE
[(u'error_id', 400), (u'error_message', u'fromdate'), (u'error_name', u'bad_parameter')]
https://api.stackexchange.com/2.2/search/advanced?&fromdate=2017-02-15&todate=2017-02-16&order=desc&tagged=SAS&sort=activity&site=stackoverflow&filter=total&key=$KEY_VALUE
[(u'error_id', 400), (u'error_message', u'fromdate'), (u'error_name', u'bad_parameter')]

marked as duplicate by Brock Adams, Community Feb 17 '17 at 6:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You probably have a syntax error like you did before. You need to post the exact code/requests you are using that causes the problem. – Brock Adams Feb 16 '17 at 20:42
  • That's better, thanks. It's now clear that this question is a duplicate. Basically, the API only allows human-readable dates when there is no key. :) ... See the linked Q&A. – Brock Adams Feb 17 '17 at 4:48

Browse other questions tagged .