2014-04-27 1 views
1

내 플라스크 응용 프로그램에서 RESTful 끝점을 만들려고하지만 끝점을 클릭하면 반환됩니다 : TypeError: organize() takes exactly 1 argument (0 given). 나는 Postman을 크롬으로 사용하여 요청을 보내고 모든 매개 변수를 form-data으로 포함했습니다.Flask 끝점의 RESTful 액세스

코드 :

@app.route('/organize', methods = ['POST']) 
def organize(request): 
    salary = request.form['salary'] 
    monthly_expenses = 0.0 

    ### Get city/state from zip or (if provided) just proceed 
    try: 
     zipcode = request.form['zipcode'] 
     citystate = zippo(zipcode) 
     citystate = json.loads(citystate) 
     city = citystate['city'] 
     state_abbr = citystate['state_abbr'] 

    except DoesNotExist: 
     city = request.form['city'] 
     state_abbr = request.form['state'] 

    ### Car stuff 
    paymentsbool = request.form['paymentsbool'] 
    try: 
     cartype = request.form['cartype'] 
     payments = request.form['payments'] 
     insurance_year = request.form['insurance'] 
     insurance = insurance_year/float(12) 
    except DoesNotExist: 
     trans = request.form['trans'] 

    ### Cell phone stuff 
    cellbool = request.form['cellbool'] 
    try: 
     cell = request.form['cell'] 
     monthly_expenses = monthly_expenses + cell 
    except DoesNotExist: 
     pass 

    ### Living expenses 
    rent = request.form['rent'] 
    nat = request.form['nat'] 
    cable = request.form['cable'] 
    gas = request.form['gas'] 
    elec = request.form['elec'] 
    groceries = request.form['groceries'] 

    monthly_sal = salary/float(12) 
    monthly_sal_af_tax = monthly_sal * .72 
    monthly_savings = monthly_sal_af_tax * .15 

    if request.form['carbool'] == True: 
     car_month = car(cartype, payments, insurance) 
     monthly_bal = monthly_bal - car_month 
     transportation = car_month 
    else: 
     monthly_bal = monthly_bal - trans 
     transportation = trans 

    monthly_expenses = monthly_expenses + rent + nat + cable + gas + elec + groceries + transportation 
    monthly_bal = monthly_sal_af_tax - monthly_savings - monthly_expenses 

    return jsonify(monthly_bal = monthly_bal, transportation = transportation, monthly_sal_af_tax = monthly_sal_af_tax, monthly_savings = monthly_savings, monthly_expenses = monthly_expenses) 

def car(type, payments, insurance): 
    gas_price = 4.00 
    cars = {1:10, 2:15, 3:20} 
    tank = cars[type] 
    gas_month = 2.00 * tank * gas_price 
    car_total = gas_month + payments + insurance 

    return car_total 
당신이 작업을 수행 할 데이터를 반환 할 수있는 가장 좋은 방법을 jsonify을했다 사용하는 경우 나 또한 궁금

? 도움을 주셔서 감사합니다. 크게 감사드립니다.

편집 : 또한 curl으로 끝점을 치려고했지만 동일한 결과를 반환합니다.

curl -X POST -d {‘zipcode’:13905, ‘paymentsbool’:0, ‘trans’:10, ‘cellbool’:0, ‘rent’:20, ‘nat’:30, ‘cable’:40, ‘gas’:50, ‘elec’:60, ‘groceries’:70} http://127.0.0.1:8080/organize --header "Content-Type:application/json" 

EDIT2 : 함수가 인수를하지 않도록 내가 request 매개 변수를 제거한이 놀러 계속. 나는 curl 전화를하려고하면 지금은

<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
curl: (3) [globbing] unmatched close brace/bracket at pos 19 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
<title>400 Bad Request</title> 
<h1>Bad Request</h1> 
<p>The browser (or proxy) sent a request that this server could not understand.</p> 

답변

2

나는이 사건이었다 그러나 나는 request.values를 사용하는 대신 request.form하여 데이터가 전송되는 액세스 할 수 있음을 발견했습니다 이유를 설명하기 시작하지 못했습니다 반환합니다.

나는 여전히 request.form이 작동하지 않는 이유에 대한 설명을 좋아하지만 이것이 내 문제를 해결했습니다.