HTTP Request POST Data

I’m attempting to use the HTTP class to login to LoveFilm programmatically. I’ve written what I thought should work but getting an incorrect response. I’ve got the following code (where U is the user’s email address and P is the password):



<br />
            values =  {'logincmd': 'login',<br />
                      'email': u,<br />
                      'password': p,<br />
                      'continue': 'Sign in'}<br />
            x = HTTP.Request('https://www.lovefilm.com/visitor/login.html', values, cacheTime=0)<br />
            PMS.Log(x)<br />




I was expecting that when I logged out the result of the HTTP request it would contain the successful login page which is a redirect to the main page. I've used HttpFox to record the HTTP POST data when I manually do it and it looks identical. I've also set the HTTP headers as follows:


<br />
    HTTP.__headers["User-agent"] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-gb) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16"<br />




Any ideas?

I ran into something similar on several plugins : https request + post do not work smoothly together. Take a look at my github repo in the (soon to be releaased) youtube plugin, in the authenticate() function I do exactly that. https://github.com/pierre1313/YouTube.bundle/blob/master/Contents/Code/init.py



The snippet you need is from right after the try: to after the f.close statement. + import urllib,urllib2



Let me know if you have any question

Thanks for that, i’ll give it a go tonight. I was surprised with what I had not working. The page returned is simply the one that I thought I just logged in on. I actually took it from the Netflix plugin as it’s doing the exact same thing. I was looking at the documentation of the HTTP class (or the lack of) and couldn’t really work out what else I might need to do.



I’m finding that 99% of this plugin is just authenticating and using OAuth. I’m hoping that the rest is easy :slight_smile:

I finally got round to trying this out (was away on holiday) and found that i’m still having issues with it. I’m finding that the response that i’m receiving is the same original page asking the user to login. I’ve pretty much copied to code included in Pierre’s example and still nothing. Is it possible that some additional header information is required in the request for the web server to correctly respond? If so, whats the best way to determine this?

I got round to working out what the problem was and thought I would just post my findings. The following code successfully logs into LoveFilm:



<br />
            values =  {'logincmd': 'login',<br />
                      'email': u,<br />
                      'password': p,<br />
                      'continue': 'Sign in'}<br />
            x = HTTP.Request('https://www.lovefilm.com/visitor/login.html', values, cacheTime=0)<br />
            x = HTTP.Request('https://www.lovefilm.com/visitor/login.html', values, cacheTime=0)<br />




As you can see, for some reason I needed to duplicate the HTTP request. It appears that the first one is not correctly handled/processed but the second correctly authenticates. The only thing I can think of is that maybe the first is required to obtain initial cookies, etc which are required by the second call. Not being from a web background, i'm not entirely sure. If anyone knows why this would be required, please let me know.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.