[TBA]: Trouble getting data off of the Blue Alliance API

Hello. I’m currently a senior with team 2823. I’ve been trying to use The Blue Alliance to gather statistical data for a school project. My programs had been working, up until today.

Here is the python code I’ve been working with:

import urllib2
import json
manyevents="mnmi","mnmi2","mndu2","mndu"]
for i in range(2013,2016):
    for j in manyevents:
        try:
            question="http://www.thebluealliance.com/api/v2/event/"+str(i)+j+"/stats"
            req=urllib2.Request(question)
            req.add_header('X-TBA-App-Id', 'd-wheezy:matchgrabber:2')
            response=urllib2.urlopen(req)
            hi=response.read()
            print hi
        except urllib2.HTTPError:
            print "event "+str(i)+j+" doesn't exist
"

The goal was to have it simply print out the result of the API call. It gave me back 403:Forbidden.
I checked my API calls against the example ones on The Blue Alliance. They seemed correct.
Still worried that it was my code, I ran this code
Again, 403.

At this point, I have no idea what is wrong. If you see something, let me know. I do have a theory, but I don’t think that it is realistic.

I did some googling to find out if it was possible that my IP was blocked or something. Instead, I stumbled across a thread on the dev group about upgrading to https. It is dated for September 7th, which would explain why my code stopped working suddenly. I don’t know much about API calls, but it seems like redirecting them to https could cause problems.
To help test this, I decided to check a scouting app that explicitly used The Blue Alliance API. FRC Krawler explicitly stated that it used the Blue Alliance API here. I downloaded it, and tested it. The app ran fine, but no events were able to be selected for any year (PS: If anybody from Knight Krawler is reading this, your app does not handle a blank event field very well).
I also tested two more popular FRC apps, FRC Spyder, and The Blue Alliance app. Both worked fine.

I’m assuming there is a bug in my code, but I can’t find it.

Greg flipped the switch to enable global https this week, so that may be the cause of your trouble. The requests should be redirecting automatically, but I don’t remember if python urllib will automatically follow redirects or not. You should update your base url and see if that helps.

Thanks for the fast response. My dad took a look at it with me in the light of day, and we managed to get it working.
Everything is working on your end. The problem is that the python library I was using (urllib2) did not support ssl. We found one that did (httplib), and lo and behold, we got the data.
I will note that this change has probably broken a lot of existing apps using the api. It isn’t hard to fix them (just add ssl), but I would recommend adding some sort of message about it on the top of the api documentation, so that when the developers discover that they are broken, they don’t have to hunt as much as me.

Thanks again!
David

Thanks for the update on what fixed it for you! I filed an issue to track this so we can make sure that api developers know how to update their apps to https.