Is there a 'how-to' anywhere that shows how to do this?  I'd really like to 
see this as a topic in Chapter 14: Other Recipes in the book.  Is it 
somewhere else where I've missed it?

-Jim


On Tuesday, January 13, 2015 at 9:30:54 AM UTC-6, Richard Penman wrote:
>
> and web2py is not 
>
> On Tue, Jan 13, 2015 at 6:04 PM, Niphlod <[email protected] <javascript:>> 
> wrote: 
> > http is stateless. 
> > 
> > 
> > On Tuesday, January 13, 2015 at 6:12:27 AM UTC+1, Richard Penman wrote: 
> >> 
> >> Yeah same data of course, but different encoding than form specifies so 
> I 
> >> expected back end to reject it. 
> >> 
> >> why it shouldn't be ? it's just different encodings to send the same 
> data 
> >> over the wire. 
> >> 
> >> On Monday, January 12, 2015 at 3:36:12 AM UTC+1, Richard Penman wrote: 
> >>> 
> >>> Strangely I found that the login forms works even when encode the data 
> as 
> >>> usual for application/x-www-form-urlencoded: 
> >>> 
> >>> cj = cookielib.CookieJar() 
> >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
> >>> html = opener.open(login_url).read() 
> >>> 
> >>> formkey = xpath.get(html, '//input[@name="_formkey"]/@value') 
> >>> data = {'email': email, 'password': password, '_formkey': formkey, 
> >>> '_formname': 'login', '_next': '/', 'remember': 'on'} 
> >>> encoded_data = urllib.urlencode(data) 
> >>> request = urllib2.Request(url, encoded_data) 
> >>> response = opener.open(request) 
> >>> 
> >>> 
> >>> Is that as expected? 
> >>> 
> >>> 
> >>> On Sunday, January 11, 2015 at 3:32:31 PM UTC+8, Richard Penman wrote: 
> >>>> 
> >>>> Do you happen to have made a script that can login to web2py? 
> >>>> It looks quite complex because have to manage the _formkey and login 
> >>>> form uses multipart/form-data instead of 
> application/x-www-form-urlencoded. 
> >>>> 
> >>>> I have this working solution using mechanize: 
> >>>> 
> >>>> br = mechanize.Browser() 
> >>>> br.open(login_url) 
> >>>> br.select_form(nr=0) 
> >>>> br['email'] = email 
> >>>> br['password'] = password 
> >>>> response = br.submit() 
> >>>> 
> >>>> 
> >>>> But looking for something using urllib2, and not loading a web2py 
> >>>> specific library. 
> >>>> 
> >>>> 
> >> -- 
> >> Resources: 
> >> - http://web2py.com 
> >> - http://web2py.com/book (Documentation) 
> >> - http://github.com/web2py/web2py (Source code) 
> >> - https://code.google.com/p/web2py/issues/list (Report Issues) 
> >> --- 
> >> You received this message because you are subscribed to a topic in the 
> >> Google Groups "web2py-users" group. 
> >> To unsubscribe from this topic, visit 
> >> https://groups.google.com/d/topic/web2py/9ipjRoSnQvY/unsubscribe. 
> >> To unsubscribe from this group and all its topics, send an email to 
> >> [email protected]. 
> >> For more options, visit https://groups.google.com/d/optout. 
> > 
> > -- 
> > Resources: 
> > - http://web2py.com 
> > - http://web2py.com/book (Documentation) 
> > - http://github.com/web2py/web2py (Source code) 
> > - https://code.google.com/p/web2py/issues/list (Report Issues) 
> > --- 
> > You received this message because you are subscribed to a topic in the 
> > Google Groups "web2py-users" group. 
> > To unsubscribe from this topic, visit 
> > https://groups.google.com/d/topic/web2py/9ipjRoSnQvY/unsubscribe. 
> > To unsubscribe from this group and all its topics, send an email to 
> > [email protected] <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to