2016-07-24 1 views
0

내 로컬 호스트가 아닌 다른 곳에서 간단한 포켓몬 API를 사용할 수있게하려고합니다. API에는 client.py와 server.py라는 두 개의 파일이 있습니다. 21 market join 명령을 실행하고 가상 IP를 받았습니다. (10.244.121.0).어떻게 Virtual IP로 21 시장에서 Bitcoin API를 호스팅 할 수 있습니까?

"http://localhost:5000/"을 요청하는 client.py 대신 "http://10.244.121.0:5000/"을 요청할 수 있도록 스크립트를 수정하려고 시도했지만 client.py를 실행할 때 해당 URL을 요청할 때 오류가 발생합니다. 저는 파이썬에 대해 매우 익숙하지 않기 때문에 10.244.121.0 주소로 요청한 사람이이 API를 사용할 수 있도록하기 위해 내가해야 할 일이 무엇인지 알지 못합니다.

client.py :

... 
# server address 
server_url = 'http://10.244.121.0/' 


def name(): 
    id = input("Please enter a Pokemon ID: ") 
    sel_url = server_url + 'name?id={0}' 
    answer = requests.get(url=sel_url.format(id)) 
    print(answer.text) 

if __name__ == '__main__': 
    name() 

server.py :

: 여기
... 
    @app.route('/name') 
    @payment.required(1) 
    def answer_question(): 

     # extract answer from client request 
     id = request.args.get('id') 
     url = 'http://pokeapi.co/api/v2/pokemon/' + id 

     response = requests.get(url) 
     pokemonData = json.loads(response.text) 
     pokemonName = pokemonData['name'] 
     print(pokemonName) 
     return pokemonName 

    if __name__ == '__main__': 
     app.run(host='0.0.0.0') 

는 가상 IP로 0.0.0.0에서 app.run 기능의 호스트를 교체 할 때 내가 오류입니다
requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.244.121.0', port=80): Max retries exceeded with url: /name?id=1 
    (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f98d6b6e470>: 
    Failed to establish a new connection: [Errno 111] Connection refused',)) 

도움을 주시면 감사하겠습니다.

Github에서의 환매 특약 : https://github.com/LAMike310/pokedex

답변

1

대신 직접 python client.py를 호출은, 지금 원격으로 내 API를 호출하는 21 buy http://10.244.121.0:5000/name?id=1를 사용할 수 있습니다.

관련 문제