googleads / googleads-python-lib

The Python client library for Google's Ads APIs
Apache License 2.0
685 stars 975 forks source link

v4.0.0 and higher: AttributeError: 'NoneType' object has no attribute 'proxy_info' when attempting to connect to DFP using a service account. #123

Closed tym-xqo closed 6 years ago

tym-xqo commented 8 years ago

Expected behavior

A service account with suitable privileges assigned should be able to connect to DFP services

Actual behavior

Attempts to connect to DFP with a valid service account result in Python AttributeError, apparently because GoogleServiceAccountClient.Refresh.proxy_config returns None.

Information

Some of my code started failing following googleads upgrade. To isolate the behavior to googleads, I composed the following simple test case, to connect to the DFP network service (based mainly on copy and paste from https://github.com/googleads/googleads-python-lib/tree/master/examples/dfp)

from googleads import dfp
from googleads import oauth2

# OAuth2 credential information. In a real application, you'd probably be
# pulling these values from a credential storage.
SERVICE_ACCOUNT_EMAIL = 'fake-pretend@developer.gserviceaccount.com'
KEY_FILE = '/secret/gcskey.p12'

# DFP API information.
APPLICATION_NAME = 'fake-pretend'

def dfp_api_client():

    oauth2_client = oauth2.GoogleServiceAccountClient(
            oauth2.GetAPIScope('dfp'), SERVICE_ACCOUNT_EMAIL, KEY_FILE)
    dfp_client = dfp.DfpClient(oauth2_client, APPLICATION_NAME)
    return dfp_client

def main(client):
    # directly from https://github.com/googleads/googleads-python-lib/blob/master/examples/dfp/v201602/network_service/get_all_networks.py
    # Initialize appropriate service.
    network_service = client.GetService('NetworkService', version='v201602')

    # Get all networks that you have access to with the current login credentials.
    networks = network_service.getAllNetworks()

    # Display results.
    for network in networks:
        print ('Network with network code \'%s\' and display name \'%s\' was found.'
             % (network['networkCode'], network['displayName']))

    print '\nNumber of results found: %s' % len(networks)

if __name__ == '__main__':
  # Initialize client object.
  dfp_client = dfp_api_client()
  main(dfp_client)

This works entirely as expected at v3.15.0, but fails with the following traceback with v4.0.0 and higher:

Traceback (most recent call last):
  File "api-test.py", line 37, in <module>
    dfp_client = dfp_api_client()# dfp.DfpClient.LoadFromStorage()
  File "api-test.py", line 16, in dfp_api_client
    oauth2.GetAPIScope('dfp'), SERVICE_ACCOUNT_EMAIL, KEY_FILE)
  File "/Users/thomas/.virtualenvs/tmp-1e8b453a8dbebace/lib/python2.7/site-packages/googleads/oauth2.py", line 203, in __init__
    self.Refresh()
  File "/Users/thomas/.virtualenvs/tmp-1e8b453a8dbebace/lib/python2.7/site-packages/googleads/oauth2.py", line 236, in Refresh
    proxy_info=self.proxy_config.proxy_info,
AttributeError: 'NoneType' object has no attribute 'proxy_info'

Steps to reproduce

  1. Install googleads 3.15.0
  2. Attempt connection to DFP API using a service account, which should work
  3. upgrade to googleads 4.x
  4. Attempt connection again
nicholaschen commented 8 years ago

Hiya,

I think this is actually caused by another issue with regards to proxies that we're working on, but I'll take another look.

Cheers, Nick

nicholaschen commented 8 years ago

My colleague Mark has found the issue, and is going to release this with the next lib push.

Thanks for your patience!

RogerWebb commented 7 years ago

I've installed the current version of googleads and the issue is still present.

From pip freeze: googleads==8.0.0

I've installed, uninstalled, reinstalled, and I still get the error.

grivescorbett commented 7 years ago

Hello!

Would you mind sharing your stack trace / code or is it exactly the same as the original issue?

msaniscalchi commented 6 years ago

Closing as this has been open for some time without any response, feel free to reopen if it remains reproducible and you can provide additional information.

Regards, Mark