urllib2.URLError: <urlopen error unknown url type: 'http> error using twill with python

Mark Devine mfmdevine at gmail.com
Mon Jun 8 13:14:18 CEST 2009


Hi
I wonder if someone could point me in the right direction. I used the
following code to access gmail but I got a
         urllib2.URLError: <urlopen error unknown url type: 'http>
error when I ran it. I have included the Traceback

import twill, string, os
b=twill.commands.get_browser()
b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB;
rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14")
b.clear_cookies()
b.go('http://www.gmail.com')
f=b.get_form("1")
b.showforms()
f['Email']= email
f['Passwd'] =password
b.clicked(f, f)
b.submit()

When I run the code I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/browser.py", line
115, in go
    self._journey('open', u)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/browser.py", line
540, in _journey
    r = func(*args, **kwargs)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 156, in open
    return self._mech_open(url, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 182, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 191, in open
    response = meth(req, response)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py",
line 573, in http_response
    response = self.parent.error(
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 208, in error
    result = apply(self._call_chain, args)
  File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain
    result = func(*args)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py",
line 129, in http_error_302
    return self.parent.open(new)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 156, in open
    return self._mech_open(url, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 182, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 191, in open
    response = meth(req, response)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py",
line 573, in http_response
    response = self.parent.error(
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 208, in error
    result = apply(self._call_chain, args)
  File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain
    result = func(*args)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py",
line 129, in http_error_302
    return self.parent.open(new)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 156, in open
    return self._mech_open(url, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 182, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 191, in open
    response = meth(req, response)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/utils.py", line
455, in http_response
    "refresh", msg, hdrs)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 208, in error
    result = apply(self._call_chain, args)
  File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain
    result = func(*args)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_http.py",
line 129, in http_error_302
    return self.parent.open(new)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 156, in open
    return self._mech_open(url, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_mechanize.py",
line 182, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "/home/mdevine/qa/aqa/mfe/site-packages/twill/other_packages/mechanize/_opener.py",
line 180, in open
    response = urlopen(self, req, data)
  File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 381, in _open
    'unknown_open', req)
  File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 337, in _call_chain
    result = func(*args)
  File "/opt/ams/mdevine/lib/python2.4/urllib2.py", line 1053, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: 'http>


Thanks

M



More information about the Python-list mailing list