0

I am using Tikona Broadband ISP in Bangalore,India. The ISP need the user to login using a web proxy.

This is how my Pi is connected:

The ethernet from ISP lands on the router and the Pi is connected to the router using ethernet.

I followed some python code as in the links below:

http://www.brijin.net/login-to-tikona/

None of the code is working as it is. I tried to change the code as well and the current code is:

#!/usr/bin/env python 

import sys
import mechanize
import time
from optparse import OptionParser
import getpass

def Login(username,password):
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('http://1.254.254.254')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    br.form.action = 'https://login.tikona.in/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F&act=null'
    #br.form.action = 'https://login.tikona.in/userportal/?requesturi=http%3a%2f%2f1%2e254%2e254%2e254%2f&ip=10%2e26%2e188%2e24&mac=fc%3a75%3a16%3ad2%3ade%3a0a&nas=tikonabangalore-3205&requestip=1%2e254%2e254%2e254&sc=76851ca3f6df9c5feaa4ac5bddd9068d'
    br.form.method = 'POST'
    print ">>> submitting.."
    response = br.submit()
    print ">>> got response"
    print response.read()
    br.select_form(name="form1")
    br["username"] = username
    br["password"] = password
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="https://login.tikona.in/userportal/newlogin.do?phone=0"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def Logout():
    print "Logging out.."
    br = mechanize.Browser()
    response = br.open('https://login.tikona.in/userportal/logout.do?svccat=1')
    print response.geturl()
    print response.info()
    print response.read()
def main():
    Login("XXXXXXXX","!@#$%&^%")

if __name__ == "__main__":
   main()

However I could not connect to the login url from the code. If I open the browser in the Pi, I can connect to the web proxy and login successfully.

UPDATE

I ran the code on my laptop (Windows 7 64 bit and Python 2.7.8 and it works fine

I do not think that the python code is having any problem, as I can connect to other sites, but not to the web-proxy somehow. And I thought it might need some small change in configs, yet clueless.

Can someone help me?

Here is the detailed error:

Traceback (most recent call last):
  File "autologin.py", line 57, in <module>
    main()
  File "autologin.py", line 54, in main
    Login("XXXXXXXX","!@#$%&^%")
  File "autologin.py", line 12, in Login
    response  = br.open('http://1.254.254.254')
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 230, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/usr/lib/python2.7/dist-packages/mechanize/_opener.py", line 204, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/dist-packages/mechanize/_http.py", line 441, in http_response
    "refresh", msg, hdrs)
  File "/usr/lib/python2.7/dist-packages/mechanize/_opener.py", line 221, in error
    result = apply(self._call_chain, args)
  File "/usr/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 571, in http_error_302
    return self.parent.open(new)
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 230, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/usr/lib/python2.7/dist-packages/mechanize/_opener.py", line 193, in open
    response = urlopen(self, req, data)
  File "/usr/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 344, in _open
    '_open', req)
  File "/usr/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 1170, in https_open
    return self.do_open(conn_factory, req)
  File "/usr/lib/python2.7/dist-packages/mechanize/_urllib2_fork.py", line 1118, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 104] Connection reset by peer>

so the primary issue seems to be something related to be able to open https and the final error message is urllib2.URLError: <urlopen error [Errno 104] Connection reset by peer>

  • I would just work out with Fiddler what data is getting posted where. Then use python to post a form that is the same to that location. But, maybe the proxy requires a cookie and that complicates things but still doable with allot more effort. – Piotr Kula Jul 17 '14 at 11:54
  • Hehe, No - It would be nice though :) Fiddler works on Windows. Install it on there, go the login page, turn on Fiddler logging, back to browser and login. Back to Fiddler. Look for the POST or GET data an examine it. Then rebuild the HTTP Request in Python on the Pi. – Piotr Kula Jul 17 '14 at 12:22
  • WHat's failing. Can you please explain a bit more because I am just going on a whim here based on my experience and not what is actually happening on your side. – Piotr Kula Jul 17 '14 at 12:44
  • 1
    You should change your title Pi cannot connect to SSL. – Piotr Kula Jul 22 '14 at 8:30
  • 1
    @Kangkan I'd blank out the username/ password first. – Lawrence Jul 24 '14 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.