Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:01:22+00:00 2026-06-13T00:01:22+00:00

I just got the following type error while executing my Python script: File /Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py,

  • 0

I just got the following type error while executing my Python script:

File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/Zach/Dropbox/stock/stk.py", line 31, in stock
url="http://finance.yahoo.com/d/quotes.csv?s="+stock+"&f=snl1"
TypeError: cannot concatenate 'str' and 'function' objects

The line causing the problem seems to be url="http://finance.yahoo.com/d/quotes.csv?s="+stock+"&f=snl1", specifically the variable stock. After research and from the little I know from previous errors, I deduced that the cause must be an issue with how the variable is defined (it’s either not a string, or possibly not defined at all); that said, I define this variable as a string in the function before:

@app.route('/', methods=['GET', 'POST'])
def home_search():
    if request.method == 'POST':
            stock = request.form['s']
            return redirect(url_for('stock'))

    return render_template('stk.html') 

And here is the function, stock where I attempt to call and display the value earlier defined:

@app.route('/stock', methods=['GET', 'POST'])
def stock():
    print type(stock)
    url="http://finance.yahoo.com/d/quotes.csv?s="+stock+"&f=snl1"
    text=urllib2.urlopen(url).read()

    return render_template('stock.html')

However, it is being defined in a different @app.route than when I call it. Shouldn’t variables in Python be stored and recalled like that, or are variables emptied when new pages are loaded? If this is the case, any suggestions for a work around or a better approach would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:01:23+00:00Added an answer on June 13, 2026 at 12:01 am

    Named functions are variables just like everything else. The stock that is being used in this line:

        url="http://finance.yahoo.com/d/quotes.csv?s="+stock+"&f=snl1"
    

    is the function that contains it. You shouldn’t rely on Python variables across requests; instead, you should pass the variable along as a request variable, e.g.

    /stock?s=whatever
    

    and then read it back out of the new request.form in the handler for that URL.


    The stock variable that you’re creating in your home_search function is a local variable that only lives for the life of the call to home_search, which ends as soon as you redirect the client to a different URL (such as /stock).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following block definition, which outputs the block of my/type just fine:
I got the following basic script who make a basic POST request (I just
I got the following webpage-builtup: <div id=menu> </div> <div id=content> <!-- you just need
I just got pagination to work on my site, but I wanted to use
I'm getting the following error message in Chrome and firefox while trying to implement
I've got the following error: 'DirectActivity' does not contain a definition for 'ddl_jobcode_Id2' and
I got the following error when running the test code. How to workaround the
Just got the new iPad, and when I touch the microphone and say a
i just got a call from Hosting company, they claimed that my application creates
I just got an email from twitter saying my keys have now been enabled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.