0

I try to UPDATE cash but I get an error I don’t understand why. Used this syntax in buy and it works fine but now File "/home/ubuntu/workspace/pset7/finance/application.py", line 243, in sell id = session["user_id"], sell = dic["price"] * shares) TypeError: 'NoneType' object is not subscriptable INFO:werkzeug:10.240.0.64 - - [27/Oct/2018 01:02:11] "POST /sell HTTP/1.1" 500 - ERROR:werkzeug:Error on request:

Check50:

:( sell handles valid sale application raised an exception (see log for details)

Log sending POST request to /login sending POST request to /sell exception raised in application: TypeError: bad operand type for unary -: 'str'

It seems like lookup function doesn’t work properly for sell.

My code in pastebin https://pastebin.com/JRz7DCdq

1 Answer 1

-1

You did not check whether quote = lookup(request.form.get("symbol")) actually returned something.

For instance, the user might have typed a non-existing symbol. Or maybe lookup could not get a result from the other website.

You should check quote before trying to use ["price"] on it.


And to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

11
  • I did. It’s on line 20 Commented Oct 26, 2018 at 15:26
  • No, you didn't. Line 20 is your lookup. And on that line you stored your result in a variable called quote. But you did not check whether quote was None. And on line 29 you try to get quote["price"], which does not work if quote happens to be None ... Commented Oct 26, 2018 at 15:37
  • I’m checking it on line 9. I think the problem is in POST GET methods. It POSTs but it doesn’t GET the values. Commented Oct 27, 2018 at 3:17
  • No, you don't. On line 9 you check whether the symbol was filled in. You never check whether the symbol is correct. And you never check whether you can get (lookup) a price for that symbol. And you never check whether you did get a price for that symbol. (Of course you could (or should)) combine those last 3 checks. But currently you skipped all 3 of them) Commented Oct 27, 2018 at 4:49
  • I’m sure if not request.form.get is checking all of it. I ran check50 and I have only one red face: :( sell handles valid sale application raised an exception (see log for details) Log sending POST request to /login sending POST request to /sell exception raised in application: TypeError: bad operand type for unary -: 'str' Commented Oct 27, 2018 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .