adwords api with Python connecting without YAML approach

1,074 views
Skip to first unread message

atro...@prosper.com

unread,
Apr 23, 2015, 7:18:03 PM4/23/15
to adwor...@googlegroups.com
I am trying the following script and getting an error that permission is denied and that is it?  This api is so convoluted it almost defeats it's purpose!  

>>> from googleads import adwords
>>> from googleads import oauth2
>>> CLIENT_SECRET = 'ELINLJVnPa_onW6xxxxxxx'
>>> REFRESH_TOKEN = '1/pRYXYjPfU67nhpKfoYBcEJpKkEgOJifHX5xdqP9kYGAMxxxxxxxxxx'
>>> DEVELOPER_TOKEN = 'aLoCgx9n5vOmqUxxxxx'
>>> USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'
>>> CLIENT_CUSTOMER_ID = '338-105-xxxx'
>>> def main(client_id, client_secret, refresh_token, developer_token, user_agent,
         client_customer_id):
  oauth2_client = oauth2.GoogleRefreshTokenClient(
      client_id, client_secret, refresh_token)

  adwords_client = adwords.AdWordsClient(
      developer_token, oauth2_client, user_agent, client_customer_id)

  customer = adwords_client.GetService('CustomerService').get()
  print 'You are logged in as customer: %s' % customer['customerId']

>>> if __name__ == '__main__':
  main(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, DEVELOPER_TOKEN, USER_AGENT,
       CLIENT_CUSTOMER_ID)

and getting this error - how do I fix this? 
.
..
...
.....
Traceback (most recent call last):
  File "<pyshell#16>", line 3, in <module>
    CLIENT_CUSTOMER_ID)
  File "<pyshell#14>", line 9, in main
    customer = adwords_client.GetService('CustomerService').get()
  File "/Library/Python/2.7/site-packages/googleads/common.py", line 294, in MakeSoapRequest
    self._header_handler.SetHeaders(self.suds_client)
  File "/Library/Python/2.7/site-packages/googleads/adwords.py", line 331, in SetHeaders
    headers=self._adwords_client.oauth2_client.CreateHttpHeader())
  File "/Library/Python/2.7/site-packages/googleads/oauth2.py", line 150, in CreateHttpHeader
    self.Refresh()
  File "/Library/Python/2.7/site-packages/googleads/oauth2.py", line 166, in Refresh
    self.disable_ssl_certificate_validation)))
  File "/Library/Python/2.7/site-packages/oauth2client-1.4.6-py2.7.egg/oauth2client/client.py", line 573, in refresh
    self._refresh(http.request)
  File "/Library/Python/2.7/site-packages/oauth2client-1.4.6-py2.7.egg/oauth2client/client.py", line 744, in _refresh
    self._do_refresh_request(http_request)
  File "/Library/Python/2.7/site-packages/oauth2client-1.4.6-py2.7.egg/oauth2client/client.py", line 773, in _do_refresh_request
    self.token_uri, method='POST', body=body, headers=headers)
  File "/Library/Python/2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1593, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/Library/Python/2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1335, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Library/Python/2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1257, in _conn_request
    conn.connect()
  File "/Library/Python/2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1021, in connect
    self.disable_ssl_certificate_validation, self.ca_certs)
  File "/Library/Python/2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 80, in _ssl_wrap_socket
    cert_reqs=cert_reqs, ca_certs=ca_certs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 891, in wrap_socket
    ciphers=ciphers)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 507, in __init__
    self._context.load_verify_locations(ca_certs)
IOError: [Errno 13] Permission denied

Josh Radcliff (AdWords API Team)

unread,
Apr 24, 2015, 12:02:50 PM4/24/15
to adwor...@googlegroups.com
Hi,

Based on the stack trace you provided, the error is occurring because you do not have permissions to the local directory containing trusted certificates.

 File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 507, in __init__
    self._context.load_verify_locations(ca_certs)
IOError: [Errno 13] Permission denied

Please try granting your user permissions to that directory. If that does not resolve the problem, please open an issue on the Python library's github page and we'll proceed from there.

Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages