我试图让我的简单的口袋妖怪API可用的东西比我的本地主机。该API有两个文件,client.py和server.py。我运行了21 market join
命令并获得了一个虚拟IP。 (10.244.121.0)。如何使用虚拟IP在21位市场上托管我的比特币API?
我试着修改我的脚本,以便代替请求“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
在app.run
功能更换主机到虚拟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