Search code examples
pythongoogle-civic-information-api

HttpError using google civic API


Im trying to request some data using the representativeInfoByAddres from the Google civic API https://developers.google.com/civic-information/docs/v2/representatives/representativeInfoByAddress but when i try to call execute() im getting an error.

from apiclient.discovery import build
add = "24783 Oakwood Circle Anaheim CA 92801"
service = build('civicinfo','v2', developerKey="key")               
rep = service.representatives().representativeInfoByAddress(address = add)
response = rep.execute()

returns

---------------------------------------------------------------------------
HttpError                                 Traceback (most recent call last)
<ipython-input-82-9fe54b12a47f> in <module>()
      2 service = build('civicinfo','v2', developerKey="drog")
      3 rep = service.representatives().representativeInfoByAddress(address = no)
----> 4 response = rep.execute()

/Users/dany_user/anaconda/lib/python2.7/site-packages/oauth2client/_helpers.pyc in positional_wrapper(*args, **kwargs)
    131                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    132                     logger.warning(message)
--> 133             return wrapped(*args, **kwargs)
    134         return positional_wrapper
    135 

/Users/dany_user/anaconda/lib/python2.7/site-packages/googleapiclient/http.pyc in execute(self, http, num_retries)
    838       callback(resp)
    839     if resp.status >= 300:
--> 840       raise HttpError(resp, content, uri=self.uri)
    841     return self.postproc(resp, content)
    842 

HttpError: <HttpError 403 when requesting https://www.googleapis.com/civicinfo/v2/representatives?alt=json&key=drog&address=24783+Oakwood+Circle+Anaheim+CA+92801 returned "Project 897797812785 is not found and cannot be used for API calls.">

What am I doing wrong?


Solution

  • The problem is that the API needs to be enable in order to work.

    Access https://console.developers.google.com and make sure under "APIs" that you have the desired API enabled