cloudendpoints / endpoints-python

A Python framework for building RESTful APIs on Google App Engine
Apache License 2.0
51 stars 17 forks source link

Unable to import "constants.py" file in project. #108

Closed zonito closed 7 years ago

zonito commented 7 years ago

My code was working with previous "google-endpoints" version, but after updating it failed to import "constants" file.

Traceback (most recent call last):
  File "lib/endpoints/endpointscfg.py", line 633, in <module>
    main(sys.argv)
  File "lib/endpoints/endpointscfg.py", line 629, in main
    args.callback(args)
  File "lib/endpoints/endpointscfg.py", line 472, in _GenDiscoveryDocCallback
    application_path=args.application)
  File "lib/endpoints/endpointscfg.py", line 304, in _GenDiscoveryDoc
    application_path=application_path)
  File "lib/endpoints/endpointscfg.py", line 183, in GenApiConfig
    module = __import__(module_name, fromlist=base_service_class_name)
...
...
...
  File "/path/to/file.py", line 421, in <module>
    class ClassName(messages.Message):
  File "/path/to/file.py", line 427, in ClassName
    limit = messages.IntegerField(4, default=constants.DEFAULT_LIMIT)
AttributeError: 'module' object has no attribute 'DEFAULT_LIMIT'

If I rename it to something else like const.py it worked.

Few more similar errors:

No handlers could be found for logger "oauth2client.contrib.multistore_file"
Traceback (most recent call last):
  File "lib/endpoints/endpointscfg.py", line 633, in <module>
    main(sys.argv)
  File "lib/endpoints/endpointscfg.py", line 629, in main
    args.callback(args)
  File "lib/endpoints/endpointscfg.py", line 455, in _GetClientLibCallback
    hostname=args.hostname, application_path=args.application)
  File "lib/endpoints/endpointscfg.py", line 417, in _GetClientLib
    application_path=application_path)
  File "lib/endpoints/endpointscfg.py", line 183, in GenApiConfig
    module = __import__(module_name, fromlist=base_service_class_name)
...
...
  File "/path/to/models.py", line 57, in ClassName
    coins = ndb.IntegerProperty(required=True, default=constants.Economy.JOIN)
NameError: name 'constants' is not defined
inklesspen commented 7 years ago

Do you have a constants.py file in your own app? I suppose it's possible it's colliding with the endpoints constants.py file, but that seems odd.

zonito commented 7 years ago

Yes, I have constants.py file in root level.

inklesspen commented 7 years ago

This is ultimately caused by the same problem as #103, I think. I will see if I can figure out a good fix.

inklesspen commented 7 years ago

2.4.3 contains this fix.