2016-08-15 2 views
1

내가 paypal 나머지 API를 사용하여 지불을 만들려고하고 반환 유지,하지만 난이 오류 응답 점점 계속 : 내 코드 여기페이팔 나머지 API는 잘못된 JSON 오류

{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"262cbdc417df7"} 

:

payment_url = 'https://api.sandbox.paypal.com/v1/payments/payment' 
headers = {"Content-Type": "application/json", "Authorization": "Bearer %s" % access_token} 
data = { 
     "intent": "sale", 
     "redirect_urls": { 
      "return_url": "http://localhost:8080/index.html", 
      "cancel_url": "http://localhost:8080/index.html" 
     }, 
     "payer": { 
      "payment_method": "paypal" 
     }, 
     "transactions": [ 
      { 
       "amount": { 
        "total": "7.47", 
        "currency": "USD" 
       }, 
       "details": { 
        "subtotal": "7.41", 
        "tax": "0.03", 
        "shipping": "0.03" 
       }, 
       "description": "This is the payment transaction description.", 
       "item_list": { 
        "items": [ 
         { 
          "quantity": "1", 
          "name": "item", 
          "price": "7.41", 
          "currency": "USD", 
          "sku": "item" 
         }] 
       } 
      } 
     ] 
    } 
    print headers 
    print data 
    r = requests.post(payment_url, headers=headers, data=data) 
    print 'payment res', r.text 

과 다음과 같은 응답 만받습니다.

{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"262cbdc417df7"} 

나는 꽤 많은 질문을 보았습니다. 이런 종류의 오류는 있지만 아직 해결 방법이 없습니다. : json formated post 데이터가 유효합니다. 그렇지 않으면 요청을 게시하는 메소드가 예외를 발생시킬 수 있습니다. 응답이 paypal 서버에서 반환되었지만 제공 한 링크에서 정보를 찾을 수 없습니다. Rest API documentation 그리고 내가 샘플을 정확히 요청을 생각한다. 내가 그리워 했는가? 모든 종류의 조언이나 솔루션을 감상 할 수있다

.

답변

0

귀하의 return_urlcancel_url이 값이 주위에 따옴표가 필요 메시지에 나와 있듯이 JSON의 형식이 잘못되었습니다.

오류 코드를 보려면 http://jsonlint.com/을 시도해보십시오.

+0

안녕하세요, 간달프, 답변 해 주셔서 감사합니다. return_url 및 cancel_url 값은 문자열 변수이며 따옴표가 있습니다. json이 유효합니다. 그렇지 않으면 게시 요청이 매개 변수에 대해 실패합니다. 문제는 paypal API에 대한 게시 요청이 완료되었지만 이상한 응답으로 나는 단서가 없다고 생각합니다. – MrAZ

관련 문제