2012-03-26 2 views
0

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() 
+1

나는 귀하의 질문에 관련되지 않기 때문에 당신을 downvoted되고 있다고 생각하지 않지만, 오히려 때문에 실제로 문제가 무엇인지 알려주지 않았거나 stacktrace 또는 기타 디버깅 정보를 제공하지 않았습니다. –

답변

2

이 라인이 있어야한다 : 나는의 다른 참조를 위해 아래에있는 내 코드를 첨부

output_val = json.loads(response.content) 
+0

답장을 보내 주셔서 감사합니다. output_val = json.load (response.content)로 변경했지만 동일한 오류입니다 ... ERROR 2012-03-26 15 : 47 : 23,890] Traceback (최근 통화 마지막) : 파일 "C : \ Python27 \ lib \ json \ __init__ "_URLFetchResult '객체에'read '속성이 없습니다 –

+0

@thong : 기본 API 읽기에 문제가 있습니다. 오류 외에도 (예 : @shay가 당신을 위해 고쳐 졌을 때, 당신은 또한'json' 모듈을 잘못 사용하고 있습니다. 특히'json.load()'는 파일과 비슷한 객체를 기대하지만'urlfetch.fetch' [문자열을 반환합니다] (http : // code.google.com/searchfr ame # Qx8E-7HUBTk/trunk/python/google/appengine/api/urlfetch.py ​​& q = urlfetch % 20 패키지 : http : //googleappengine%5C.googlecode%5C.com&l=250). 한 걸음 뒤로 물러나서 사용하려는 API를 읽어 보시기 바랍니다. 올바른'json' 메소드는'loads'입니다. – bernie

+0

@bernie : 설명을 가져 주셔서 감사합니다. 게시 된 모델을 호출했을 때 수행 한 작업은 PiCloud 문서를 따랐습니다. 여기 링크는 http://docs.picloud.com/rest.html#query-format –

관련 문제