Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > urllib2.URLError: <urlopen error unknown url type: 'http> error usingtwill with python

Reply
Thread Tools

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

 
 
Mark Devine
Guest
Posts: n/a
 
      06-08-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
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      06-08-2009
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
 
Reply With Quote
 
 
 
 
amadain
Guest
Posts: n/a
 
      06-29-2009
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
urllib2.URLError: <urlopen error unknown url type: http Coonay Python 2 03-13-2009 06:35 AM
Assign an unknown value to an unknown variable Vincent Arnoux Ruby 1 08-11-2006 06:12 PM
URL - substitution of a correct URL by a GUID like URL in favorites. Just D. ASP .Net Mobile 0 08-11-2004 04:26 PM
redirect URL's, return URL's, and URL Parameters Jon paugh ASP .Net 1 07-10-2004 05:29 AM
Cannot access URL (unknown host exception) Nilson Java 3 07-24-2003 09:04 AM



Advertisments