-1

I'm trying to make my simple Pokemon API available on something other than my localhost. The API has two files, client.py and server.py. I ran the 21 market join command and got a virtual IP. (10.244.121.0).

I tried modifying my script so that instead of the client.py requesting "http://localhost:5000/" it would request "http://10.244.121.0:5000/", but when I run the client.py I get an error when requesting that url. I'm pretty new to Python so I don't know what I need to do in order to make this API available to anyone who requests it on the 10.244.121.0 address.

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

Here is the error I get when replacing the host in the app.run function from 0.0.0.0 to the virtual 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',))

Any help would be appreciated!

Github repo: https://github.com/LAMike310/pokedex

Mike
  • 2,633
  • 6
  • 31
  • 41

1 Answers1

1

Instead of calling python client.py directly, I can now use 21 buy http://10.244.121.0:5000/name?id=1 to call my API remotely.

Mike
  • 2,633
  • 6
  • 31
  • 41