Cannot retrieve data from Strawpoll API
Question: I have a simple python code that goes to [this
link](http://maps.googleapis.com/maps/api/geocode/json?address=googleplex&sensor=false)
and retrieves it's data. Here is the code

    
    
    import urllib, json
    url = "http://maps.googleapis.com/maps/api/geocode/json?address=googleplex&sensor=false"
    htmlfile = urllib.urlopen(url)
    data = json.loads(htmlfile.read())
    print data
    

Running the code returns the data from the url.

    
    
    {u'status': u'ZERO_RESULTS', u'results': []}
    

I'd like to do the same, but for Strawpoll. After reading through their [API
documentation](https://github.com/strawpoll/strawpoll/wiki/API), it appears to
be the same formula. Going to the strawpoll link for testing, it shows me the
same content structure as the google link shown above. The API Documenation
states that " All resources will return data in JSON." But I am not getting
any data back, I'm getting errors. The code is exactly the same, but with the
edited url.

    
    
    import urllib, json
    url = "http://strawpoll.me/api/v2/polls/1/"
    htmlfile = urllib.urlopen(url)
    data = json.loads(htmlfile.read())
    print data
    

Running the code gives me a view errors, I would post an image but
stackoverflow won't let me...

The last error I receive is "ValueError: No JSON object could be loaded". But
the API Documentation said that data is returned as JSON.

Removing the `json.loads` gives me pure html instead. Here is the code for
that. Again, exactly the same but removed the `json.loads`.

    
    
    import urllib
    url = "http://strawpoll.me/api/v2/polls/1/"
    htmlfile = urllib.urlopen(url)
    data = htmlfile.read()
    print data
    

What am I doing wrong?


Answer: I just ran your code and looked into the HTML response. Perhaps you are not
setting the right HTTP headers? It says that access is denied, but I'm not
sure why that would be. I'd recommend using [requests](http://www.python-
requests.org/en/latest/).

    
    
    >>> url = "http://strawpoll.me/api/v2/polls/1/"
    >>> import requests
    >>> requests.get(url).json()
    {u'id': 1, u'multi': False, u'votes': [14683, 31165, 5635, 7397], u'options': [u'Sucker punch ', u'Pirates of carribian ', u'Prison logic', u'Witchhunter'], u'title': u'What movie should we watch'}
    

Since you are not opening the URL from a browser, it could be an effort by
strawpoll.me to protect their content from being scraped. In fact, I found
this line in the HTML response:

    
    
    <p>The owner of this website (strawpoll.me) has banned your access based on your browser's signature (***).</p>
    

