GAE와 PiCould를 처음 접했고 GAE에서 게시 된 함수를 호출 할 때 몇 가지 기본적인 질문이 있습니다. 게시 된 기능을 호출하는 방식이 인식되지 않는 것 같습니다. 그럼 나 한테 제안 해 줄 수있어?Google App Engine에서 PiCloud 함수를 호출 할 때의 문제
도움 주셔서 감사합니다.
업데이트 : 사람들이이 질문이 가치가 없다고 생각하는 이유는 확실하지 않습니다. GAE에서는 순수 파이썬 파일 만 허용하기 때문에 다른 언어 (예 : Fortran77)로 작성된 모델을 찾아야합니다. 따라서 일부 비 파이썬 프로그램은 PiCloud와 같은 다른 클라우드 서버에 업로드 된 다음 GAE에서 호출 할 수 있습니다. 사람들의 도움으로 (감사합니다!)이 문제를 파악했습니다.
import os
os.environ['DJANGO_SETTINGS_MODULE']='settings'
from google.appengine.ext.webapp.util import run_wsgi_app
import webapp2 as webapp
import json
import base64
#import urllib2
import urllib
from google.appengine.api import urlfetch
api_key='1111'
api_secretkey='adsad'
####define and publish a function######
def square(x):
"""Returns square of a number"""
print 'Squaring %d' % x
return x*x
cloud.setkey(api_key, api_secretkey)
cloud.rest.publish(square, "square_func")
url = 'https://' + 'api.picloud.com/r/3303/square_func'
input_val=22
#######call the function#################
base64string = base64.encodestring('%s:%s' % (api_key, api_secretkey))[:-1]
http_headers = {'Authorization' : 'Basic %s' % base64string}
data = urllib.urlencode({"x":input_val})
response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers)
jid= json.loads(response.content)['jid']
output_st = 'queued'
#
while output_st=="queued":
response_st = urlfetch.fetch(url='https://api.picloud.com/job/?jids=%s&field=status' %jid, headers=http_headers)
output_st = str(json.loads(response_st.content)['info']['%s' %jid]['status'])
url_val = 'https://api.picloud.com/job/result/?jid='+str(jid)
response_val = urlfetch.fetch(url=url_val, method=urlfetch.GET, headers=http_headers)
output_val = json.loads(response_val.content)['result']
class Page(webapp.RequestHandler):
def get(self):
html = """<table width="600" border="1">
<tr>
<th width="480" scope="col">Outputs</div></th>
<th width="120" scope="col">Value</div></th>
</tr>
<tr>
<td>Input</td>
<td>%s</td></tr>
<tr>
<td>picloud jid</td>
<td>%s</td></tr>
<tr>
<td>picloud status</td>
<td>%s</td></tr>
<tr>
<td>picloud results</td>
<td>%s</td></tr>
</table>"""%(input_val, jid, output_st, output_val)
self.response.out.write(html)
app = webapp.WSGIApplication([('/.*', Page)], debug=True)
def main():
run_wsgi_app(app)
if __name__ == '__main__':
main()
나는 귀하의 질문에 관련되지 않기 때문에 당신을 downvoted되고 있다고 생각하지 않지만, 오히려 때문에 실제로 문제가 무엇인지 알려주지 않았거나 stacktrace 또는 기타 디버깅 정보를 제공하지 않았습니다. –