Python Flask Basics Character Builder Cookies

"[Errno 98] Address already in use" error on Workspaces

I'm trying to follow along on workspace, but after trying to fix variable data not found I can't run the Flask script app.py anymore. I only have 1 workspace open, I've tried closing and reopening it but it seems almost like workspaces is keeping my old process ongoing I don't know for what reason and I've no idea how to reset Workspaces to fix this and carry on with tutorial.

Source:

import json
from flask import (Flask, render_template, redirect,
                   url_for, request, make_response)

app = Flask(__name__)


def get_saved_data():
  try:
    data = json.loads(request.cookies.get('character'))
  except TypeError:
    data = {}
  return data


@app.route('/')
def index():
  return render_template('index.html', saves=data)


@app.route('/save', methods=['POST'])
def save():
  #import pdb; pdb.set_trace()
  response = make_response(redirect(url_for('index')))
  data = get_saved_data()
  data.update(dict(request.form.items()))
  response.set_cookie('characer', json.dumps(data))
  return response


app.run(debug=True, host='0.0.0.0', port=8000)

Seems this was somehow made by a couple of typos rather than what I thought of first. I think, this can be marked as closed / solved as I re-wrote code and progressed in tutorial.

2 Answers

Hello Guys.

I have encountered that same error message from time to time and in the cases where I can't get rid of it my solution is normally the following:

In the workspaces console I type "ps -aux", this returns a list of the active processes with their relative PIDs.

At this point I type "kill" followed by the PID number of the processes I want to kill.

After this you should be able to relaunch your app as normal.

PLEASE NOTE that, if I am remembering correctly, this solution can lead to a loss of unsaved edits and updates, so I would recommend to use it only when you are really struggling.

I hope this helps.

Vittorio

That's a working-ish solution, thanks! Just curiosity, what platform is the Treehouse Workspaces based on?

I actually experience the same problem again. It would be very welcome if somebody could identify what exactly causes it. Else, ofc, I can try implementing version control but it's not very... conventional, because I'm afraid the Workspaces doesn't offer that by default :(

The thing is, no it's not stopping me from completing the course. Yet I still encounter this problem in some cases and it would be helpful if somebody could explain me what that problem really is and how to possibly avoid it so to say.