동의어 api를 치면 단어에 대한 동의어 목록을 만들려고합니다. 나는 Flask와 요청 패키지를 사용하고 있습니다.Python Requests 패키지가 url을 두 번 조회합니다
플라스크 경로를 통해 웹 폼에서 정보를 얻은 후에이 함수를 한 번만 호출합니다.
코드 :
import requests
from flask import Flask, request, render_template, flash
import environment
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
keywords = request.form["key1"]
synonyms = syn_look(keywords)
return render_template("index.html", syns=synonyms)
return render_template("index.html")
def syn_look(word):
URL = "http://words.bighugelabs.com/api/2/%s/%s/json"
request_url = URL %(environment.thesaurus_api_key, word)
r = requests.get(request_url)
print r.status_code
if __name__ == "__main__":
app.debug = False
app.run()
상태 인쇄 두 번
출력 :
* Restarting with reloader
* Detected change in 'server.py', reloading
* Restarting with reloader
127.0.0.1 - - [10/Jan/2014 17:22:03] "GET/HTTP/1.1" 200 -
200
404
프로그램의 정확한 결과를 알려주시겠습니까? – Keeler
{* 리로더로 다시 시작 * 'server.py'의 변경 사항을 감지하고로드하는 중 * 리로더로 다시 시작 127.0.0.1 - [10/Jan/2014 17:22:03] "GET/HTTP/1.1"200 - 200} } – user3183689
애플리케이션의 전체 코드, 특히'syn_look' 메소드를 호출하는 부분을 게시하십시오. –