Dewey
Dewey

Reputation: 776

devappserver.py for app engine std on localhost is clearing os.uname & crashing in ctypes

I have foolishly reinstalled all my Python 2.7 dependencies and it's broken something. If you notice on line 1, os.uname() has a valid value, but by the time GAE calls ctypes module (line 3), it has been emptied and my local server won't respond to the client.

This feels a bit over my head & I'd appreciate any guidance.

os.uname() is: 19.3.0
INFO     2020-03-04 19:11:42,584 instance.py:294] Instance PID: 8624
os.uname() is: 
ERROR    2020-03-04 19:11:43,311 wsgi.py:269] 
Traceback (most recent call last):
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 311, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
    __import__(cumulative_path)
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/service_backend/main.py", line 7, in <module>
    import endpoints as google_cloud_endpoints
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/endpoints/__init__.py", line 29, in <module>
    from .api_config import api, method
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/endpoints/api_config.py", line 44, in <module>
    import attr
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/__init__.py", line 5, in <module>
    from . import converters, exceptions, filters, validators
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/filters.py", line 7, in <module>
    from ._compat import isclass
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/_compat.py", line 139, in <module>
    set_closure_cell = make_set_closure_cell()
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/_compat.py", line 129, in make_set_closure_cell
    ctypes = import_ctypes()
  File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/_compat.py", line 95, in import_ctypes
    import ctypes
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 29, in <module>
    if int(_os.uname()[2].split('.')[0]) < 8:
ValueError: invalid literal for int() with base 10: ''

Upvotes: 1

Views: 277

Answers (2)

Bryce McLean
Bryce McLean

Reputation: 11

Try editing the stubs file located within the devappserver2/python/runtime.

google_appengine/google/appengine/tools/devappserver2/python/runtime/stubs.py

From:

    def fake_uname():

      """Fake version of os.uname."""

      return ('Linux', '', '', '', '')

To:

    def fake_uname():
      """Fake version of os.uname."""
      return ('Linux', 'local', '19', 'Darwin Kernel Version 19', 'x86_64')

It isn’t a great long term solution because updates to the gcloud tool chain will likely wipe out the changes.

Upvotes: 1

hynek
hynek

Reputation: 4126

attrs hasn't been using ctypes since 19.2.0, so the solution is to get your dependencies somehow updated.

Upvotes: 1

Related Questions