2013-04-22 2 views
1
APIURL ='http://localhost:6543/api/patches/alice_8b84090712bce46e15a8107839cefe/e5678' 
data = { 
    'patch_id' : 'e5678', 
    'queue_id' : 'alice_8b84090712bce46e15a8107839cefe', 
} 
response = requests.get(APIURL, data=data) 

나는 코니스 피라미드 REST API를 테스트하기 위해 위 코드를 가지고 있습니다.피라미드는 http 데이터를 읽습니다.

그러나 data=data 매개 변수를 통해 입력 한 데이터를 읽는 데 문제가 있습니다.

@resource(collection_path='/api/patches', path="/api/patches/{queue_id}/{patch_id}") 
class Patch(object): 
    def __init__(self, request): 
     self.request = request 

    def get(self): 
     """ 
     """ 
     queue_id = self.request.matchdict.get('queue_id', '') 
     patch_id = self.request.matchdict.get('patch_id', '') 
     data = { 
      'queue_id': 'e12525e1f90ad5e7395a965', 
      'patch_id': 'a9651a8259a666c0032f343', 
      'node_id': 'bef3a2adc76415b2be0f6942b5111f6c5e5b7002', 
      'message': 'This is a patch on feature2.', 
      'datetime': '.....', 
     } 

     #TODO call the patch method to get the public attributes 

     return {'error':{}, 'data': data} 

답변

5

요청 that parameter is used to provide the body of the response 같이 data 파라미터에 제공되는 데이터를 무시한다 (그리고 GET은 신체가없는)

이것은이 엔드 포인트에 서버 기능이다. 당신은 쿼리 문자열 인수를 전달 괜찮 경우 - 즉 :

http://localhost:6543/api/patches?queue_id=12345&patch_id=910 

다음 대신 params 키워드 인수를 사용할 수 있습니다 그렇지 않으면

requests.get(APIURL, params=data) 

을, 당신이 urlparse에서 urljoin를 사용하여 URL을 만들 수 있습니다 표준 라이브러리 :

APIURL = "http://localhost:6543/api/patches" 
with_queue = urljoin(APIURL, queue_id) 
with_patch = urljoin(with_queue, patch_id) 
response = requests.get(with_patch)