Thanks Kurtis!

On Wed, Sep 5, 2012 at 2:48 PM, Kurtis Mullins <[email protected]> wrote:
> Sure,
>
> To submit a cookie, check this out:
> http://stackoverflow.com/questions/3334809/python-urllib2-how-to-send-cookie-with-urlopen-request
>
> To harvest a CSRF Token from a page (for example, as part of a form), here's
> one example solution I found:
> http://stackoverflow.com/questions/3145178/get-contents-of-a-tags-using-python
> -- of course you'd want to grab the appropriate HTML Element.
>
> Here's an example of setting and getting cookies:
> http://stackoverflow.com/questions/5606083/how-to-set-and-retrieve-cookie-in-http-header-in-python
>
> Here's some docs on the how to make the CSRF System happy:
> https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-it-works
>
> On Wed, Sep 5, 2012 at 2:38 PM, Larry Martell <[email protected]>
> wrote:
>>
>> I have no idea how that would be done (neither extracting the token
>> nor passing it via urllib). I'm googling this, but if you know and
>> want to share, that would be great.
>>
>> On Wed, Sep 5, 2012 at 1:50 PM, Kurtis Mullins <[email protected]>
>> wrote:
>> > Actually, I've got another idea for you. You mentioned you wanted to
>> > simply
>> > access using urllib. Maybe you could create a small script to extract a
>> > CSRF
>> > token from the login page, login with a known (test) user, and continue
>> > passing and extracting the CSRF token as needed?
>> >
>> >
>> > On Wed, Sep 5, 2012 at 1:06 PM, Larry Martell <[email protected]>
>> > wrote:
>> >>
>> >> Thanks - but now I'm getting
>> >>
>> >> NameError: "global name 'get_backends' is not defined"
>> >>
>> >>
>> >> On Wed, Sep 5, 2012 at 12:59 PM, Kurtis Mullins
>> >> <[email protected]> wrote:
>> >> > Looks like you just need a quick:
>> >> >
>> >> > from django.contrib.auth.models import User
>> >> >
>> >> > towards the top :)
>> >> >
>> >> >
>> >> > On Wed, Sep 5, 2012 at 12:57 PM, Larry Martell
>> >> > <[email protected]>
>> >> > wrote:
>> >> >>
>> >> >> On Wed, Sep 5, 2012 at 12:21 PM, anthony tresontani
>> >> >> <[email protected]> wrote:
>> >> >> > We are using a middleware to enforce a user login:
>> >> >> >
>> >> >> > class AutoAuthMiddleware(object):
>> >> >> >     """
>> >> >> >         Middleware for testing purpose only.
>> >> >> >         Can enforce the user login.
>> >> >> >     """
>> >> >> >
>> >> >> >     def process_request(self, request):
>> >> >> >         enforce_user = request.GET.get("enforce_user", None)
>> >> >> >         if hasattr(request, "user") and not enforce_user:
>> >> >> >             return
>> >> >> >
>> >> >> >         user = User.objects.filter(username = enforce_user)
>> >> >>
>> >> >>
>> >> >> I'm getting: 'NameError: "global name 'User' is not defined"' on the
>> >> >> above line. This is the same issue I was running into when I was
>> >> >> trying to hard code the initialization of a request.user object.
>> >> >> Where
>> >> >> is that defined?
>> >> >>
>> >> >>
>> >> >> >         if user:
>> >> >> >             backend = get_backends()[0]
>> >> >> >             user = user[0]
>> >> >> >             user.backend = "%s.%s" % (backend.__module__,
>> >> >> > backend.__class__.__name__) #fake authentication
>> >> >> >             login(request, user)
>> >> >> >
>> >> >> > You can add that to your testing environnement MIDDLEWARE_CLASSES.
>> >> >> >
>> >> >> > Then you can just go to any url and add ?enforce_user=<username>
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > On 05/09/12 17:56, Larry Martell wrote:
>> >> >> >
>> >> >> > On Wed, Sep 5, 2012 at 9:36 AM, Kurtis Mullins
>> >> >> > <[email protected]>
>> >> >> > wrote:
>> >> >> >
>> >> >> > I don't see why not.
>> >> >> >
>> >> >> > I've been trying to do that, but it's still complaining.
>> >> >> >
>> >> >> > Are you running unit tests (testing scripts) or are you
>> >> >> > just using the browser for testing?
>> >> >> >
>> >> >> > I'm trying to do performance measuring. I have a list of all the
>> >> >> > urls
>> >> >> > accessed over the past few months by a client, along with metrics
>> >> >> > on
>> >> >> > their execution times. I want to run all those on a new server
>> >> >> > we've
>> >> >> > set up and collect metrics and compare them. I have a python
>> >> >> > script
>> >> >> > that uses urllib2 but, I can't run anything without logging in.
>> >> >> > I've
>> >> >> > tried to login from python, but I get a 403. I also tried using
>> >> >> > the
>> >> >> > requests module - that doesn't give me the 403, but doesn't log me
>> >> >> > in
>> >> >> > - it just returns the login page as if the login failed.
>> >> >> >
>> >> >> > On Wed, Sep 5, 2012 at 11:24 AM, Larry Martell
>> >> >> > <[email protected]>
>> >> >> > wrote:
>> >> >> >
>> >> >> > On Wed, Sep 5, 2012 at 9:22 AM, Kurtis Mullins
>> >> >> > <[email protected]>
>> >> >> > wrote:
>> >> >> >
>> >> >> > If any of your templates/views depend upon a request.user object,
>> >> >> > you'll
>> >> >> > run
>> >> >> > into issues because that will not exist without "logging in". I'm
>> >> >> > not
>> >> >> > sure
>> >> >> > of a good way around this off-hand without knowing more about your
>> >> >> > site.
>> >> >> > Sorry!
>> >> >> >
>> >> >> > Yes, they do depend on a request.user object. Can I hard code the
>> >> >> > initialization of it?
>> >> >> >
>> >> >> > On Wed, Sep 5, 2012 at 11:18 AM, Larry Martell
>> >> >> > <[email protected]>
>> >> >> > wrote:
>> >> >> >
>> >> >> > We have a django app that requires the users to login. For some
>> >> >> > testing we want to do, we want to disable this so the app can be
>> >> >> > run
>> >> >> > without logging in. Is there some way to easily do this? I've
>> >> >> > tried
>> >> >> > commenting out all the @login_required decorations, but then I was
>> >> >> > getting a 403. I tried commenting out the 'if not
>> >> >> > controller.has_access' lines, but then I was getting
>> >> >> > 'Report.owner"
>> >> >> > must be a "User" instance.' Before I hack up the code any more, is
>> >> >> > there some way to just globally disable the need to login?
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "Django users" group.
>> >> >> > To post to this group, send email to
>> >> >> > [email protected].
>> >> >> > To unsubscribe from this group, send email to
>> >> >> > [email protected].
>> >> >> > For more options, visit this group at
>> >> >> > http://groups.google.com/group/django-users?hl=en.
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "Django users" group.
>> >> >> > To post to this group, send email to
>> >> >> > [email protected].
>> >> >> > To unsubscribe from this group, send email to
>> >> >> > [email protected].
>> >> >> > For more options, visit this group at
>> >> >> > http://groups.google.com/group/django-users?hl=en.
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "Django users" group.
>> >> >> > To post to this group, send email to
>> >> >> > [email protected].
>> >> >> > To unsubscribe from this group, send email to
>> >> >> > [email protected].
>> >> >> > For more options, visit this group at
>> >> >> > http://groups.google.com/group/django-users?hl=en.
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "Django users" group.
>> >> >> > To post to this group, send email to
>> >> >> > [email protected].
>> >> >> > To unsubscribe from this group, send email to
>> >> >> > [email protected].
>> >> >> > For more options, visit this group at
>> >> >> > http://groups.google.com/group/django-users?hl=en.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "Django users" group.
>> >> >> > To post to this group, send email to
>> >> >> > [email protected].
>> >> >> > To unsubscribe from this group, send email to
>> >> >> > [email protected].
>> >> >> > For more options, visit this group at
>> >> >> > http://groups.google.com/group/django-users?hl=en.
>> >> >>
>> >> >> --
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups
>> >> >> "Django users" group.
>> >> >> To post to this group, send email to [email protected].
>> >> >> To unsubscribe from this group, send email to
>> >> >> [email protected].
>> >> >> For more options, visit this group at
>> >> >> http://groups.google.com/group/django-users?hl=en.
>> >> >>
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Django users" group.
>> >> > To post to this group, send email to [email protected].
>> >> > To unsubscribe from this group, send email to
>> >> > [email protected].
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/django-users?hl=en.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to [email protected].
>> >> To unsubscribe from this group, send email to
>> >> [email protected].
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to