Setup with Python and Oauth 2.0

582 views
Skip to first unread message

Eliza Chang

unread,
Jan 31, 2014, 3:40:16 PM1/31/14
to google-doubleclick...@googlegroups.com
I am having trouble getting set-up on the DFP API. I keep running into the same error (that seems like an authentication error). 

Here are some example commands run in Python 2.7.6 on OS X Mavericks:

>>> from adspygoogle import DfpClient
>>> client = DfpClient()
>>> forecast_service = client.GetService('ForecastService', version='v201311')
>>> forecast = forecast_service.GetForecastById('47061610')[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/GenericApiService.py", line 290, in CallMethod
    self._ReadyOAuth()
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/GenericApiService.py", line 255, in _ReadyOAuth
    self._RefreshCredentialIfNecessary(self._headers['oauth2credentials'])
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/GenericApiService.py", line 270, in _RefreshCredentialIfNecessary
    self._headers['oauth2credentials'].refresh(httplib2.Http())
  File "build/bdist.macosx-10.9-intel/egg/oauth2client/client.py", line 516, in refresh
  File "build/bdist.macosx-10.9-intel/egg/oauth2client/client.py", line 653, in _refresh
  File "build/bdist.macosx-10.9-intel/egg/oauth2client/client.py", line 682, in _do_refresh_request
  File "/Library/Python/2.7/site-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 1570, 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.8-py2.7.egg/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Library/Python/2.7/site-packages/httplib2-0.8-py2.7.egg/httplib2/__init__.py", line 1252, in _conn_request
    conn.connect()
  File "/Library/Python/2.7/site-packages/httplib2-0.8-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.8-py2.7.egg/httplib2/__init__.py", line 80, in _ssl_wrap_socket
    cert_reqs=cert_reqs, ca_certs=ca_certs)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 387, in wrap_socket
    ciphers=ciphers)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 141, in __init__
    ciphers)
ssl.SSLError: [Errno 185090050] _ssl.c:343: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

What does this mean, and how can I fix it?

The steps I took to set up are:
  1. installed adspygoogle, 
  2. ran config.py and input all my credentials (including a refresh token generated from generate_refresh_token.py)
  3. which generated dfp_api_auth.pkl and dfp_api_config.pkl (which should hold my OAuth 2.0 credentials) 
Any help on this would be much appreciated; I've been trying to figure this out for days and am not sure where I am going wrong!

Many thanks.

Nicholas Chen (DFP API Team)

unread,
Jan 31, 2014, 4:30:37 PM1/31/14
to google-doubleclick...@googlegroups.com
Hi Eliza,

The SSLError thrown here is normally seen when the Python runtime tries to find the certs file on your machine, but fails to do so.

This seems like an environment problem, with the cacerts file not being read for SSL purposes.

A general search lead me to this Stackoverflow post:


Which seems to suggest changing permissions or running as root might fix the issue.

Best,
Nicholas Chen, DFP API Team

Eliza Chang

unread,
Feb 2, 2014, 9:36:04 PM2/2/14
to dfpapi-advi...@google.com, google-doubleclick...@googlegroups.com, Joseph Ranzenbach
Hi Nicholas,

Thanks for your reply. I changed the permissions on both cacert.pem and cacert.txt (using chmod 644). After doing so (as well as generating a new refresh token), I have a different type of error:

$ python get_forecast_by_id.py
Traceback (most recent call last):
  File "get_forecast_by_id.py", line 42, in <module>
    forecast = forecast_service.GetForecastById(line_item_id)[0]
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/GenericApiService.py", line 290, in CallMethod
    self._ReadyOAuth()
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/GenericApiService.py", line 255, in _ReadyOAuth
    self._RefreshCredentialIfNecessary(self._headers['oauth2credentials'])
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/adspygoogle/common/GenericApiService.py", line 270, in _RefreshCredentialIfNecessary
    self._headers['oauth2credentials'].refresh(httplib2.Http())
  File "build/bdist.macosx-10.9-intel/egg/oauth2client/client.py", line 516, in refresh
  File "build/bdist.macosx-10.9-intel/egg/oauth2client/client.py", line 653, in _refresh
  File "build/bdist.macosx-10.9-intel/egg/oauth2client/client.py", line 710, in _do_refresh_request
oauth2client.client.AccessTokenRefreshError: invalid_client

Any ideas on how to proceed here?

Thanks,
Eliza


--
You received this message because you are subscribed to a topic in the Google Groups "Google's DoubleClick for Publishers API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-doubleclick-for-publishers-api/XSX2iDAPmNQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-p...@googlegroups.com.
To post to this group, send email to google-doubleclick...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-doubleclick-for-publishers-api.
For more options, visit https://groups.google.com/groups/opt_out.

Eliza Chang

unread,
Feb 3, 2014, 10:06:39 AM2/3/14
to Nicholas Chen, google-doubleclick...@googlegroups.com, Joseph Ranzenbach
Update: I was able to receive a response from the API by using the use_oauth2.py example code, and copying/pasting the calls I wanted into its main() function. After days of trying to connect, this is wonderful progress! 

The only downside is that running the program requires retrieving the refresh token each time and manually entering it. Any tips on how to circumvent this?

Thanks!
Eliza

Nicholas Chen (DFP API Team)

unread,
Feb 4, 2014, 2:22:06 PM2/4/14
to google-doubleclick...@googlegroups.com, Nicholas Chen, Joseph Ranzenbach
Hi Eliza,

Wonderful!

Your refresh token (assuming you haven't asked for too many) should last for a relatively long time, and should be reused until it states that it has expired.

With this, you can request a new access token with each session or request (as those have an expiry lifetime of 3600 seconds by default).

Nicholas Chen, DFP API Team

To unsubscribe from this group and all its topics, send an email to google-doubleclick-for-publishers-api+unsubscribe@googlegroups.com.
To post to this group, send email to google-doubleclick-for-publishers-api@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages