Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

I'm doing some testing on my app, and I let it run on a machine this afternoon while I was away. When I got back, I was geting 503 throttle violation errors from my API calls.

I was calling the "questions" endpoint at a rate of once per minute, passing a "min" date value to limit the returned questions to just those that have been submitted since my last poll. In the case where "has_more" was true in the response, I was retrying (with the page incremented) at a rate of once every 5 seconds. To my understanding, this is far less than the established maximum number of requests per unit time. I believe I was at about 300 requests total when I hit the throttle.

I've also got code in place to honor the "backoff" attribute if it was present, but that code was untested and it's possible it doesn't work.

I lost the console output, so I don't know exactly what happened when the feces impacted the high-speed rotating blades. Now, all of my requests return 502 errors, even though it's been about 2.5 hours since the "event."

Request url:

https://api.stackexchange.com/2.0/questions?sort=creation&pagesize=5&min=1325870128&site=gaming&order=asc&key=XXXXXXXX&page=1

Where XXXXXXXX is my API key. I can't get the quota since all endpoints are returning the same throttle violation error. In earlier testing, it was reading a max quota of 10,000.

Specific data that is being returned:

{u'error_id': 502, u'error_message': u'too many requests from this IP', 
 u'error_name': u'throttle_violation'}

Here's the API usage graph for my app, I can't grab the entire runtime graph (resolution issues), but there should be enough of it there to ensure that there's nothing odd going on:

enter image description here

What's a good way to debug this issue? I haven't found any good tools for showing a spike in my API requests at any higher resolution than daily. The data I can get back from the API is pretty much just "you were bad, go away" which isn't terribly helpful either.

UPDATE: At about 19:10 UTC Jan 6, the condition cleared and API requests are succeeding again. I'm going to let it continue to run to see if there's further issues, but I'd still like to root cause why this happened so I can avoid it in the future.

UPDATE2: I let the app run overnight, and as soon as I'd hit 301 requests, I hit another throttle violation, even though I am using a key with quota_max = 10,000

requesting stackexchange url: https://api.stackexchange.com/2.0/questions?sort=creation&pagesize=5&min=1325913207&site=gaming&order=asc&key=REDACTED&page=1

success!  calling callback.
{u'has_more': False, u'items': [], u'quota_max': 10000, u'quota_remaining': 9699}

2 minutes later:


requesting stackexchange url: https://api.stackexchange.com/2.0/questions?sort=creation&pagesize=5&min=1325913328&site=gaming&order=asc&key=REDACTED&page=1

Error:
{u'error_id': 502, u'error_message': u'too many requests from this IP', u'error_name': u'throttle_violation'}

The two requests were made 120 seconds apart, and you'll note that the final successful response did not contain a "backoff" element.

UPDATE 3 - I tried again today with an access_token parameter, and I'm currently at around 400 requests 10 seconds apart without throttling. The requests continued to succeed until my quota was around 1717, at which point the access_token timed out:

{u'error_id': 402, u'error_message': u'expired', u'error_name': u'invalid_access_token'}
share|improve this question
    
I'm now making requests once every 2 minutes, and I'm still getting nothing but 503 errors. It seems like I should be able to make multiple requests per second without hitting the throttle limits, so any input would be most helpful. –  agent86 Jan 6 '12 at 15:43
    
On the homepage of Stackapps, on the left click Manage Applications, choose your app, then on the left click Query Statistics, this will provide you with a graph to show how many times the method has been requested and when. If the graph doesn't explain the problem take a screenshot and post it in your question. –  Jonathan. Jan 6 '12 at 16:59
    
Also you are including your application key in the request right? If you don't the request quota is only 300, compared to the 10,000 you get with a key. –  Jonathan. Jan 6 '12 at 17:00
    
@Jonathan. I added the additional data requested. In testing prior to the throttle violation, I had 10k as my max quota. I've also included the usage graph that shows I'd gotten to about 300 on the 5th before the violation kicked in. –  agent86 Jan 6 '12 at 17:29
    
Do you have any other apps using the API running on your IP address (maybe on another machine on your network)? Try generating an access token for you on your app and putting that in the query, if the request returns normally, then the problem is not your app or the API, but another program using API. –  Jonathan. Jan 6 '12 at 18:27
    
@Jonathan. I rent the IP as part of a VPS package, and this is the one and only app running on it and accessing the stack API. I had problems earlier this week where my quota was decreasing even though I wasn't using it, so I'm betting this is another bug along those lines. –  agent86 Jan 6 '12 at 18:44
    
Try adding an access token, it should help narrow things down (more information the better) when Kevin see this. –  Jonathan. Jan 7 '12 at 19:25
    
@Jonathan., I don't have a flow for that in my app currently. I'll see what I can do. –  agent86 Jan 7 '12 at 19:35
    
From your update, it seems to definitely be a bug. But you can just get an access_token using your browser the url and query parameters are in the documentation, then just copy the access_token and put it in the url your app uses. Actually it might help a bit, because if the access_token and app key don't match it will send back a different error. –  Jonathan. Jan 7 '12 at 23:05
    
@Jonathan. - there's no web component to the tool whatsoever, and the URLs in the key were all bogus, so I had to set one up in order to get an access_token. I ran the test with the token and edited the question to show the results. –  agent86 Jan 8 '12 at 18:07
    
Not that it helps, but I ran into the same issue on polling the API, even with ?key={my_key} in all the request. Fortunately, I could just switch from my home IP to a different one by running my machine's traffic through my phone (not ideal for speed, but it bought me enough time to call it a day and wait for the reset). –  patridge Jan 8 '12 at 22:24
    
I had a problem similar to this and it was caused by one query (which I only run once) which was missing the key. Running keyed queries more than 300 times causes an unkeyed query to fail for throttle violation. Fixing the missing key fixed the problem. –  Dennis Williamson Apr 17 at 22:19
add comment

1 Answer

up vote 1 down vote accepted

I believe this has been fixed.

Let me know if you run into it again.

share|improve this answer
    
My dummy access_token has run out, so I've switched back to not using one. I should know if it's still a problem in about 3,000 seconds :) –  agent86 Jan 9 '12 at 19:09
    
I just checked and I'm at 9,423 with no error so far. –  agent86 Jan 9 '12 at 20:42
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .