My "index" was working fine, but it no longer works and i get the 500 internal server error now, which has been happening after migrating to the new IDE. I does not seem to be my code. Here is what appears in my terminal upon logging onto the web application of pset8:

~/ $ cd ~/environment/pset8/finance/
~/environment/pset8/finance/ $ flask run
 * Serving Flask app "application.py" (lazy loading)
 * Environment: development
 * Debug mode: off
 * Running on https://808d061b-7cdd-4348-ab06-3ede74c26f12- 
ide.cs50.xyz:8080/ (Press CTRL+C to quit)  
 * Restarting with stat
INFO:werkzeug: - - [05/Jul/2019 18:21:57] "GET / 
HTTP/1.0" 302 -
INFO:werkzeug: - - [05/Jul/2019 18:21:57] "GET /login 
HTTP/1.0" 200 -
INFO:werkzeug: - - [05/Jul/2019 18:21:57] "GET 
/static/styles.css HTTP/1.0" 200 -
DEBUG:cs50:SELECT * FROM users WHERE username = 'John'
INFO:werkzeug: - - [05/Jul/2019 18:22:02] "POST /login 
HTTP/1.0" 302 -
DEBUG:cs50:SELECT stock, company_name, SUM(shares_number) FROM 
portfolio GROUP BY stock
DEBUG:cs50:SELECT stock FROM portfolio WHERE id= 1 GROUP BY stock
ERROR:flask.app:Exception on / [GET]
Traceback (most recent call last):
  File "/opt/pyenv/versions/3.7.2/lib/python3.7/site- 
packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/opt/pyenv/versions/3.7.2/lib/python3.7/site- 
packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/pyenv/versions/3.7.2/lib/python3.7/site- 
packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/pyenv/versions/3.7.2/lib/python3.7/site- 
packages/flask/_compat.py", line 35, in reraise
raise value
File "/opt/pyenv/versions/3.7.2/lib/python3.7/site- 
packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/pyenv/versions/3.7.2/lib/python3.7/site- 
packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ubuntu/environment/pset8/finance/helpers.py", line 34, in 
return f(*args, **kwargs)
File "/home/ubuntu/environment/pset8/finance/application.py", line 57, 
in index
dict_ticker = lookup(ticker)
File "/home/ubuntu/environment/pset8/finance/helpers.py", line 44, in 
response = requests.get(f"https://cloud- 
File "/opt/pyenv/versions/3.7.2/lib/python3.7/urllib/parse.py", line 
823, in quote_plus
string = quote(string, safe + space, encoding, errors)
File "/opt/pyenv/versions/3.7.2/lib/python3.7/urllib/parse.py", line 
807, in quote
return quote_from_bytes(string, safe)
File "/opt/pyenv/versions/3.7.2/lib/python3.7/urllib/parse.py", line 
832, in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes
INFO:werkzeug: - - [05/Jul/2019 18:22:03] "GET / 
HTTP/1.0" 500 -
INFO:werkzeug: - - [05/Jul/2019 18:22:03] "GET 
/static/styles.css HTTP/1.0" 200 -
INFO:werkzeug: * Detected change in 
'/home/ubuntu/environment/pset8/finance/application.py', reloading
* Restarting with stat
INFO:werkzeug: * Restarting with stat

Is the TypeError showing, referring to a line 832 of a file? I don't know what file that is. Why am I getting this error? Thank you.


Did you run the export API_KEY=.... in the terminal beforehand? That variable has to be set each time you open a new session.

  • Thank you for your suggestion, but it didn't solve the problem. I didn't know that I needed to run export API_KEY=value every time I open a new session, and I did that this last time, but the problem still remains. – John Abdelmalek Jul 6 '19 at 1:49
  • You must be passing something other than a string to the lookup function. Not sure why it would have worked before but not now if you made no other changes. – curiouskiwi Jul 6 '19 at 4:27
  • Seems that I had made a mistake. I had commented out a line of code that apparently I shouldn't have. It has now been uncommented and things are working again. Sorry, curiouskiwi! Thank you for your help! – John Abdelmalek Jul 6 '19 at 5:47
  • No problem. Glad you figured it out. – curiouskiwi Jul 6 '19 at 9:34

You must log in to answer this question.

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