GoogleCloudPlatform / cloud-profiler-python

Stackdriver Profiler Python agent is a tool that continuously gathers CPU usage information from Python applications
Apache License 2.0
27 stars 23 forks source link

AttributeError: module 'pyparsing' has no attribute 'downcaseTokens' #104

Closed ray-ray closed 1 year ago

ray-ray commented 2 years ago

Starting today, when I import googlecloudprofiler, I get this traceback;

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/app/collection/__init__.py", line 16, in <module>
    import googlecloudprofiler
  File "/usr/local/lib/python3.7/site-packages/googlecloudprofiler/__init__.py", line 19, in <module>
    from googlecloudprofiler import client
  File "/usr/local/lib/python3.7/site-packages/googlecloudprofiler/client.py", line 29, in <module>
    import google_auth_httplib2
  File "/usr/local/lib/python3.7/site-packages/google_auth_httplib2.py", line 23, in <module>
    import httplib2
  File "/usr/local/lib/python3.7/site-packages/httplib2/__init__.py", line 52, in <module>
    from . import auth
  File "/usr/local/lib/python3.7/site-packages/httplib2/auth.py", line 20, in <module>
    auth_param_name = token.copy().setName("auth-param-name").addParseAction(pp.downcaseTokens)
AttributeError: module 'pyparsing' has no attribute 'downcaseTokens'

Looks like the latest pyparsing release changed the name of these functions: https://pyparsing-docs.readthedocs.io/en/latest/whats_new_in_3_0_0.html#other-discontinued-features

upcaseTokens and downcaseTokens - convert to using pyparsing_common.upcase_tokens and downcase_tokens
ray-ray commented 2 years ago

As a workaround, I having pinned pyparsing in my requirements.txt:

pyparsing==2.4.7
amchiclet commented 2 years ago

Thanks for reporting this. Looks like the root cause is being tracked here.

We can possibly add some workaround in cloud-profiler-python while waiting for that to be resolved.

I'm currently occupied with other tasks, but I'll do my best to take a look at this in 1-2 weeks. If your workaround starts breaking badly, please let us know.

punya commented 1 year ago

I think this is fixed in httplib 0.20.2 (https://github.com/httplib2/httplib2/issues/207#issuecomment-957159308). I was able to import googlecloudprofiler successfully after installing google-cloud-profiler in a clean virtualenv.

Recording versions for posterity:

$ pip freeze
cachetools==5.2.0
certifi==2022.9.24
charset-normalizer==2.1.1
google-api-core==2.10.1
google-api-python-client==2.63.0
google-auth==2.12.0
google-auth-httplib2==0.1.0
google-cloud-profiler==4.0.0
googleapis-common-protos==1.56.4
httplib2==0.20.4
idna==3.4
protobuf==4.21.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==3.0.9
requests==2.28.1
rsa==4.9
six==1.16.0
uritemplate==4.1.1
urllib3==1.26.12