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

M

Mark Devine

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
 
S

Steven D'Aprano

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.
 
A

amadain

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.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top