[英]Cant get libraries to compile cloud endpoints python
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)
This is my file when I run endpointscfg.py it tells me that it is not a ProtoRPC service. 当我运行endpointscfg.py时,这是我的文件,它告诉我它不是ProtoRPC服务。 I have tried application,api_root,and ffsapi.
我试过了application,api_root和ffsapi。 The code deploys fine works fine just can't get the compiling of libraries to work.
代码部署良好,但无法使库正常工作。
Here is the yaml file if that helps 这是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
In this case, because you're only implementing the API with one class, you should decorate the PatientApi
class with the @endpoints.api
decorator instead of calling endpoints.api()
separately and assigning the result to a variable. 在这种情况下,由于仅使用一个类来实现API,因此应使用
@endpoints.api
装饰器修饰PatientApi
类,而不是分别调用endpoints.api()
并将结果分配给变量。 Then, you'd create the API server with: 然后,您将使用以下命令创建API服务器:
application = endpoints.api_server([PatientApi], restricted=False)
Finally, to generate the Open API specification using endpointscfg.py, you'd pass in main.PatientApi
(assuming your source file is called main.py). 最后,要使用endpointscfg.py生成Open API规范,您将传入
main.PatientApi
(假设您的源文件称为main.py)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.