Re: [Tutor] if request.method == 'GET': NameError: global name 'request' is not defined

2016-01-18 Thread sudipto manna
Thanks All.
The import request was missing and the issue was resolved upon calling that
module and initializing it.

Thanks for the guidance.

Regards,
Sudipto Manna

On Mon, Jan 18, 2016 at 3:55 AM, Cameron Simpson  wrote:

> On 17Jan2016 20:13, sudipto manna  wrote:
>
>> Here is the code snippet:
>>
>> File#FlaskTest2.py
>>
>> from flask import Flask
>>
>
> You need to import "request" from flask as well:
>
>  from flask import Flask, request
>
> For others on this list: the Flask framework presents the current web
> request as a thread local global called "request"; simplifies writing
> handlers as the request information is readily available without having to
> pass it through function calls.
>
> Cheers,
> Cameron Simpson 
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if request.method == 'GET': NameError: global name 'request' is not defined

2016-01-18 Thread sudipto manna
Here is the code snippet:

File#FlaskTest2.py

from flask import Flask

app = Flask(__name__)

#Make an app.route() decorator here
@app.route("/puppies/", methods = ['GET' , 'POST'])
def puppiesFunction():
  if request.method == 'GET':
  return getAllPuppies()

  elif request.method == 'POST':
   return makeANewPuppy()

File# FlaskTendpointTester2.py
import httplib2
import json
import sys

print "Running Endpoint Tester\n"
address = raw_input("Please enter the address of the server you want to
access, \n If left blank the connection will be set to '
http://localhost:5000':   ")
if address == '':
address = 'http://localhost:5000'
#Making a GET Request
print "Making a GET Request for /puppies..."

Virtual machine is running on port:5000

and the error trace seen on when the endpoint code is executed on localhost
port:5000

Traceback (most recent call last):

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1836, in __call__

return self.wsgi_app(environ, start_response)

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1820, in wsgi_app

response = self.make_response(self.handle_exception(e))

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1403, in handle_exception

reraise(exc_type, exc_value, tb)

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1817, in wsgi_app

response = self.full_dispatch_request()

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1477, in full_dispatch_request

rv = self.handle_user_exception(e)

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1381, in handle_user_exception

reraise(exc_type, exc_value, tb)

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1475, in full_dispatch_request

rv = self.dispatch_request()

  File
"/Users/sudiptomanna/anaconda2/lib/python2.7/site-packages/flask/app.py",
line 1461, in dispatch_request

return self.view_functions[rule.endpoint](**req.view_args)

  File "/Users/sudiptomanna/fullstack/vagrant/PythonData/FlaskTest2.py",
line 8, in puppiesFunction

if request.method == 'GET':

NameError: global name 'request' is not defined


Regards,

Sudipto Manna

On Sun, Jan 17, 2016 at 7:17 PM, Alan Gauld 
wrote:

> On 17/01/16 23:15, sudipto manna wrote:
> > Hi All,
> > I am running a python flask project for fetching the endpoint.
> >
> > Please find the files attached.
>
> OK, This is a text based mailing list so attachments tend
> not to make it through the server. If they are not too long post them
> here, or if they are bigger put them on a pastebin. However...
>
> Flask is not part of the standard library so a little bit
> off topic for this list, you may be better off asking on
> the Flask support forum.
>
> Howe er it is a common framework so somebody here might
> be able to help.
>
> > When the endpoint file is executed its returning this error:
> > "if request.method == 'GET': NameError: global name 'request' is not
> > defined"
>
> We really need to see the full error trace and the full
> context around the reported fault - ideally the full file.
> The probability is that the error is telling the truth
> and 'request' is not defined yet. Is it part of Flask?
> Should you have prepended the module name?
> Is the spelling/case correct?
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] if request.method == 'GET': NameError: global name 'request' is not defined

2016-01-17 Thread sudipto manna
Hi All,
I am running a python flask project for fetching the endpoint.

Please find the files attached.
Parent file: FlaskTest2.py
Endpoint Tester File: FlaskTendpointTester2.py

Process:
1. Execute the file FlaskTest2.py --> python FlaskTest2.py
# This will execute the file on the terminal and will be ready to listen
the requests coming RESTFUL API's written in python, s as to validate the
endpoint and checking the various methods like: GET, POST, PUT, DEETE etc.

2. Execute the FlaskTendpointTester2.py -- > python FlaskTendpointTester2.py
#This will open the terminal and indicate the local hit n which the
FlaskTest2.py is executed and will respond back wth all the response; like
the GET, POST, PUT, DELETE method will be called.

Issue#
When the endpoint file is executed its returning this error:
"if request.method == 'GET': NameError: global name 'request' is not
defined"

Here we are looking if the FlaskTest2.py file has any GET, POST, DELETE
method or not.

The error is coming on the terminal(on same Machine 2 working terminals are
opened) where the FlaskTest2.py is run.


Appreciate the help.

Regards,
Sudipto Manna
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor