私の単純なポケモン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