0

I'm importing the Stackdriver logging python library on an AWS Lambda function, like so:

    import google.cloud.logging
    from google.cloud.logging.handlers import CloudLoggingHandler
    from google.cloud.logging.handlers.transports.sync import SyncTransport
    client = google.cloud.logging.Client.from_service_account_json('serviceAccountKey.json')
    handler = CloudLoggingHandler(client, name='slackbot', transport=SyncTransport)
    stackdriver = logging.getLogger('slackbot')
    stackdriver.setLevel(logging.DEBUG)
    stackdriver.addHandler(handler)

I'm seeing this error, but it doesn't seem to be from any particular line of my code, but from the library itself?

Error processing line 10 of /var/task/gapic_google_cloud_logging_v2-0.91.3-py3.6-nspkg.pth:

23:59:18
Traceback (most recent call last):
23:59:18
File "/var/lang/lib/python3.6/site.py", line 168, in addpackage
23:59:18
exec(line)
23:59:18
File "<string>", line 1, in <module>
23:59:18
File "<frozen importlib._bootstrap>", line 557, in module_from_spec

23:59:18
AttributeError: 'NoneType' object has no attribute 'loader'

23:59:18
Remainder of file ignored

23:59:18
Error processing line 10 of /var/task/proto_google_cloud_logging_v2-0.91.3-py3.6-nspkg.pth:

23:59:18
Traceback (most recent call last):

23:59:18
File "/var/lang/lib/python3.6/site.py", line 168, in addpackage

23:59:18
exec(line)

23:59:18
File "<string>", line 1, in <module>

23:59:18
File "<frozen importlib._bootstrap>", line 557, in module_from_spec

23:59:18
AttributeError: 'NoneType' object has no attribute 'loader'

23:59:18
Remainder of file ignored
skunkwerk
  • 2,920
  • 2
  • 37
  • 55

1 Answers1

1

I was running into a similar problem with the Google Cloud PubSub module. I resolved it by moving the .pth file that raises the error. Try running the command:

mv /var/task/proto_google_cloud_logging_v2-0.91.3-py3.6-nspkg.{pth,IGNORE}

These *.pth files are run whenever Python is started. If you actually open up the .pth file and examine it, what it does is scrape information about the Google Cloud API packages and versions available on the system, and set attributes for each sub-module of the Google Cloud API (corresponding to different cloud services).

I don't know what causes it to break, but in my case I had three different versions (prefixed with proto_, google_cloud_, and gapic_), each with 10-20 *.pth files related to various services (BigQuery, PubSub, Datastore, etc.), and only one of them (the one related to PubSub) was causing problems. When I renamed it the error message went away, and I was still able to import and use PubSub via the Python API.

charlesreid1
  • 4,360
  • 4
  • 30
  • 52