Search code examples
pythonflaskgoogle-apiandroid-management-api

Google-APIs and python returns attribute errors or memory adress


IM working with google apis and python. I am trying to use the android-management-api

When calling the API as how examples are stating it im getting: AttributeError: 'str' object has no attribute 'request' but im following the example request that google themselves state

when i dont use the .execute in the code im getting an memory adress but this is all im getting. <bound method HttpRequest.execute of <googleapiclient.http.HttpRequest object at 0x000001F2D34F2C08>>

I followed the examples from google and from realpython.com but this keeps being a blocker

the code that works perfectly in google colab:

#this imports the discovery build
from app import androidmanagement, enterprise_name

devices = androidmanagement.enterprises().devices().list(parent=enterprise_name, pageSize=200).execute()['devices']
device_list = list({'name': device['name'], 'policy': device['policyName'], 'SN': device['hardwareInfo']['serialNumber']} for device in devices)
print(device_list)

when going through the API explorer it gives me an JSON back with the same credentials.

when using:

devices = androidmanagement.enterprises().devices().list(parent=enterprise_name, pageSize=200).execute()
print(devices)

Im getting: AttributeError: 'str' object has no attribute 'request'

What am i doing wrong??


Solution

  • Solved:

    Authorization was not enough through an API-key,
    Sadly google could have documented this to prevent this issue.
    Created a custom Authflow to run in Flask.
    The Credentials are now saved as a cookie that is readable through the whole application