【问题标题】:Cant get libraries to compile cloud endpoints python无法获取库来编译云端点 python
【发布时间】:2017-03-15 01:59:52
【问题描述】:
class Patient(EndpointsModel):
    user = EndpointsUserProperty(required=True, raise_unauthorized=True)
    date_of_birth = EndpointsDateProperty()
    age = ndb.IntegerProperty()

    def calculate_age(self):
        today = date.today()
        birthday = self.date_of_birth
        self.age = today.year - birthday.year - ((today.month, today.day) < (birthday.month , birthday.day))

    def _pre_put_hook(self):
        if self.date_of_birth:
            self.calculate_age()

....
api_root = endpoints.api(name='ffsapi', version='vGDL',
                    description='API for whole app')


@api_root.api_class(resource_name="patient")
class PatientApi(remote.Service):

    @Patient.method(
                    request_fields=('name', 'date_of_birth'),
                    name='insert',
                    path='patient',
                    http_method='POST')
    def insert_patient(self,patient):
        if patient.date_of_birth: # TODO find a better way
            if patient.date_of_birth.year <1900:
                raise endpoints.BadRequestException('date <= 1900')
        patient.put()
        return patient

    @Patient.query_method(user_required=True,
                          query_fields=['name'],
                          name='query',
                          path='patient')
    def query_patient(self,query):
        return query
....
application = endpoints.api_server([api_root], restricted=False)

这是我运行 endpointscfg.py 时的文件,它告诉我它不是 ProtoRPC 服务。我已经尝试过应用程序、api_root 和 ffsapi。代码部署正常,但无法编译库。

如果有帮助,这里是 yaml 文件

application: ******(im just hiding it)
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.application

# Endpoints handler
- url: /_ah/spi/.*
  script: main.application


libraries:
- name: webapp2
  version: "2.5.2"
# Needed for endpoints/users_id_token.py.
- name: pycrypto
  version: "2.6"
- name: endpoints
  version: 1.0

【问题讨论】:

    标签: python google-app-engine google-cloud-endpoints endpoints-proto-datastore


    【解决方案1】:

    在这种情况下,因为您只使用一个类来实现 API,所以您应该使用 @endpoints.api 装饰器来装饰 PatientApi 类,而不是单独调用 endpoints.api() 并将结果分配给变量。然后,您将创建 API 服务器:

    application = endpoints.api_server([PatientApi], restricted=False)

    最后,要使用 endpointscfg.py 生成 Open API 规范,您需要传入 main.PatientApi(假设您的源文件名为 main.py)。

    【讨论】:

      猜你喜欢
      • 2013-09-15
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 2013-05-03
      • 2013-12-22
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多