Note that there are some explanatory texts on larger screens.

plurals
  1. POHandle non standard 401 headers with machanize
    primarykey
    data
    text
    <p>I am trying to automate login to this page <a href="http://portal.globaltransit.net/" rel="nofollow">http://portal.globaltransit.net/</a> the thing is the page return a 401 header when you first reach the page but does not show standerd bassic http auth page rather a http form. Here is the output of <code>curl -vvv http://portal.globaltransit.net/</code></p> <pre><code>* About to connect() to portal.globaltransit.net port 80 (#0) * Trying 124.158.236.65... connected * Connected to portal.globaltransit.net (124.158.236.65) port 80 (#0) &gt; GET / HTTP/1.1 &gt; User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15 &gt; Host: portal.globaltransit.net &gt; Accept: */* &gt; &lt; HTTP/1.1 401 Unauthorized &lt; Date: Thu, 14 Nov 2013 07:18:06 GMT &lt; Server: Apache &lt; X-Powered-By: PHP/5.2.11 &lt; Set-Cookie: symfony=1960d9b76a5f9fc3b00786e126cc69af; path=/ &lt; Content-Length: 1211 &lt; Content-Type: text/html; charset=utf-8 &lt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel="shortcut icon" href="/favicon.ico" /&gt; &lt;link rel="stylesheet" type="text/css" media="screen" href="/css/main.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="/login" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;&lt;label for="signin_username"&gt;Username&lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input type="text" name="signin[username]" id="signin_username" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&lt;label for="signin_password"&gt;Password&lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input type="password" name="signin[password]" id="signin_password" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&lt;label for="signin_remember"&gt;Remember&lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input type="checkbox" name="signin[remember]" id="signin_remember" /&gt;&lt;input type="hidden" name="signin[_csrf_token]" value="6bdf80ca900038ada394467752593135" id="signin__csrf_token" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" value="sign in" /&gt; &lt;a href="/request_password"&gt;Forgot your password?&lt;/a&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>when i try to use machanize to load the page with the following script</p> <pre><code>import mechanize import mimetypes import logging import urllib2 from urlparse import urlparse import cookielib from base64 import b64encode class Browser: def __init__(self, url): br = mechanize.Browser() br.set_handle_robots(False) # no robots br.set_handle_refresh(False) br.set_handle_redirect(True) br.set_debug_http(True) cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # can sometimes hang without this br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] self.page = br.open(url).read() print self.page if __name__ == '__main__': browser = Browser("http://portal.globaltransit.net/") </code></pre> <p>I get the following error <code>mechanize._response.httperror_seek_wrapper: HTTP Error 401: Unauthorized</code>. I was wondering if there any way to get mechanize to ignore the 401 returned by the server so I can process the form.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload