ローカルホスト以外で簡単な Pokemon API を利用できるようにしようとしています。API には client.py と server.py の 2 つのファイルがあります。21 market join
コマンドを実行し、仮想 IP を取得しました。(10.244.121.0)。
client.py が「http://localhost:5000/」を要求する代わりに「http://10.244.121.0:5000/」を要求するようにスクリプトを変更しようとしましたが、 client.py を実行するとその URL をリクエストするときにエラーが発生しました。10.244.121.0
私は Python にかなり慣れていないので、この 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()
サーバー.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')
app.run
関数内のホストを0.0.0.0
仮想 IPに置き換えるときに発生するエラーは次のとおりです。
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