2016-07-24 17 views
0

私の単純なポケモンAPIを私のlocalhost以外で利用できるようにしようとしています。 APIには、client.pyとserver.pyという2つのファイルがあります。私は21 market joinコマンドを実行し、仮想IPを取得しました。 (10.244.121.0)。Bitcoin APIを仮想IPで21市場にホストするにはどうすればよいですか?

"http://localhost:5000/"を要求するclient.pyの代わりに "http://10.244.121.0:5000/"を要求するようにスクリプトを修正しようとしましたが、client.pyを実行するとそのURLを要求するときにエラーが発生します。私はかなりPythonの新機能ですので、このAPIを10.244.121.0アドレスでリクエストしている誰でも利用できるようにするために、私は何をする必要があるのか​​分かりません。

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') 

ここでは0.0.0.0から仮想IPに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を使用することができます。

関連する問題