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

Discussion in 'Python' started by Mark Devine, Jun 8, 2009.

  1. Mark Devine

    Mark Devine Guest

    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
     
    Mark Devine, Jun 8, 2009
    #1
    1. Advertising

  2. Re: urllib2.URLError: <urlopen error unknown url type: 'http> errorusingtwill with python

    On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote:

    > 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()



    My bet is that the above is not the actual code you have run. I bet that
    the offending line is actually something like the following:

    b.go("'http://www.gmail.com")

    Note that there is a single character difference.

    Consider the last two lines of the traceback:

    > raise URLError('unknown url type: %s' % type)
    > urllib2.URLError: <urlopen error unknown url type: 'http>



    It seems to be saying that the url type is 'http -- note the leading
    single quote.


    --
    Steven
     
    Steven D'Aprano, Jun 8, 2009
    #2
    1. Advertising

  3. Mark Devine

    amadain Guest

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

    On Jun 8, 12:58 pm, Steven D'Aprano <st...@REMOVE-THIS-
    cybersource.com.au> wrote:
    > On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote:
    > > 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()

    >
    > My bet is that the above is not the actual code you have run. I bet that
    > the offending line is actually something like the following:
    >
    > b.go("'http://www.gmail.com")
    >
    > Note that there is a single character difference.
    >
    > Consider the last two lines of the traceback:
    >
    > >     raise URLError('unknown url type: %s' % type)
    > > urllib2.URLError: <urlopen error unknown url type: 'http>

    >
    > It seems to be saying that the url type is 'http -- note the leading
    > single quote.
    >
    > --
    > Steven


    Actually that is the exact code run from a python shell. Try it
    yourself. I could not find anybody who successfully automated sending
    a gmail through python with twill so if you know how I would greatly
    appreciate any pointers.
     
    amadain, Jun 29, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    2,724
  2. Chris
    Replies:
    0
    Views:
    1,065
    Chris
    Jul 10, 2005
  3. Replies:
    1
    Views:
    979
    Rene Pijlman
    Mar 10, 2006
  4. Coonay
    Replies:
    2
    Views:
    2,769
    Coonay
    Mar 13, 2009
  5. icarreon
    Replies:
    0
    Views:
    1,763
    icarreon
    Jan 10, 2012
Loading...

Share This Page