473,545 Members | 524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urllib2, problems with a webserver

Hello,
My aim is to write a small application to use free sms-sending services
in a more convenient way than with a web-browser. I found:
http://wwwsearch.sourceforge.net/mechanize/ (which resemples the perl
variant). With mechanize I should manage to interact with the website
through python, like supplying usernames, filling the message form, etc.
All well so far, I have installed it and tested it locally,
seems to work well.
But this piece of code:
-------------------------------------
from mechanize import Browser

b = Browser()
b.open("http://freesms.no:88/")
assert b.viewing_html( )

print b.geturl()
print b.title()
-------------------------------------

Give me this error:

Traceback (most recent call last):
File "./sms_sender.py", line 11, in ?
b.open("http://freesms.no:88/")
File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py",
line 106, in open
def open(self, url, data=None): return self._open(url, data)
File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py",
line 133, in _open
self._parse_htm l(self.response )
File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py",
line 464, in _parse_html
for token in p.tags(*(self.u rltags.keys()+["base"])):
File "/usr/lib/python2.3/site-packages/pullparser.py", line 90, in
iter_until_exce ption
yield fn(*args, **kwds)
File "/usr/lib/python2.3/site-packages/pullparser.py", line 194,
in get_tag
tok = self.get_token( )
File "/usr/lib/python2.3/site-packages/pullparser.py", line 177,
in get_token
self.feed(data)
File "/usr/lib/python2.3/HTMLParser.py", line 108, in feed
self.goahead(0)
File "/usr/lib/python2.3/HTMLParser.py", line 148, in goahead
k = self.parse_star ttag(i)
File "/usr/lib/python2.3/HTMLParser.py", line 239, in parse_starttag
endpos = self.check_for_ whole_start_tag (i)
File "/usr/lib/python2.3/HTMLParser.py", line 314,
in check_for_whole _start_tag
self.error("mal formed start tag")
File "/usr/lib/python2.3/HTMLParser.py", line 115, in error
raise HTMLParseError( message, self.getpos())
HTMLParser.HTML ParseError: malformed start tag, at line 2, column 1365
--------------------------------------

By commenting out line 314 of HTMLParser.py and adding "return"
I manage to continue. And everything seems to work (albeit not tested
much). This is ofcourse not an acceptable solution...

How come I get this error?

Can the server software be a issue?
According to netcraft the server runs Microsoft-IIS/5.0
Thanks,

Erling


Jul 18 '05 #1
1 3591
Erling Ringen Elvsrud <er*******@kill ozapHALLO.com.i nvalid> writes:
[...]
HTMLParser.HTML ParseError: malformed start tag, at line 2, column 1365 [...] How come I get this error?

[...]

Bad HTML. (OK, I haven't actually looked at the HTML, but it's 100/1
that HTMLParser is at fault.)

I hope eventually to rewrite mechanize to use htmllib.HTMLPar ser
everywhere, and not use HTMLParser.HTML Parser. The former is less
fussy. That just means rewriting pullparser to support both classes,
I think. Not too hard (see ClientForm for how to do it -- why not
write a patch?-).

In the meantime, the best thing to do is to pre-process the HTML.
Inconvenient, I know. Also a bit inconvenient is that the only way to
do this ATM with mechanize is to write a tiny urllib2 handler class
(.http_response () is the handler method you want, which only exists in
the as-yet-unreleased Python 2.4, and in ClientCookie, which has a
near-identical interface to urllib2; mechanize uses ClientCookie, not
urllib2). See posts to the wwwsearch-general mailing lists for sample
code.

Don't mix urllib2 and ClientCookie, BTW (with the exception of classes
that exist in urllib2 but not in ClientCookie: you can use those
urllib2 classes with ClientCookie).

HTH
John
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3945
by: Matthew Wilson | last post by:
I am writing a script to check on my router's external IP address. My ISP refreshes my IP very often and I use dyndns for the hostname for my computer. My Netgear mr814 router has a webserver that uses HTTP basic authorization. My script uses urllib2 to connect to the router and read the html page with the current external IP address. This...
0
1849
by: Gil Tal | last post by:
Hi, I use urllib2 to download a redirected url and I get an exception from the bowels of urllib2. It seems that urllib2 implements some super sophisticated self check and tries to control the access to attributes using lots of calls to hasattr(the builtin function) and a custom __getattr__() on the Request class that perfroms some checks and...
4
6678
by: Bo Yang | last post by:
Hi , Recently I use python's urllib2 write a small script to login our university gateway . Usually , I must login into the gateway in order to surf the web . So , every time I start my computer , it is my first thing to do that open a browser to login the gateway ! So , I decide to write such a script , sending some post information to...
1
1117
by: goyatlah | last post by:
I'm trying to figure out how to get the exact opened url after a urlopen in urllib2. Say you have a link : http://myhost/mypath : what do I get back, - the file mypath on myhost - the file index.html on myhost/mypath, - or maybe something else. Snd what about the following: http;//myhost/index.htm where index.htm is actually a directory....
2
12381
by: ken | last post by:
Hi, i have the following code to load a url. My question is what if I try to load an invalide url ("http:// www.heise.de/"), will I get an IOException? or it will wait forever? Thanks for any help. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener)
1
3350
by: Magnus.Moraberg | last post by:
Hi, I have the following code - import urllib2 from BeautifulSoup import BeautifulSoup proxy_support = urllib2.ProxyHandler({"http":"http:// 999.999.999.999:8080"}) opener = urllib2.build_opener(proxy_support)
3
4463
by: Phillip B Oldham | last post by:
In my attempt to learn python in a weekend, I've fallen foul at line 10 of my second scripting attempt. Basically I'm writing a simple spider, but currently I'm unable to find any documentation on making HEAD requests using the urllib2 library to test whether a file exists on a remote webserver. I've checked the docs on urllib2 from...
8
5364
by: Sam | last post by:
I'm using urllib2 and accepting gzip and deflate. It turns out that almost every site returns either normal text or gzip. But I finally found one that returns deflate. Here's how I un-gzip: compressedstream = StringIO.StringIO(data) gzipper = gzip.GzipFile(fileobj=compressedstream) data = gzipper.read()
2
3905
by: silk.odyssey | last post by:
I am getting the following error trying to download an html page using urllib2. urllib2.HTTPError: HTTP Error 204: NoContent The url is of this type: http://www.amazon.com/gp/offer-listing/B000KJX3A0%3FSubscriptionId%3D183VXJS74KNQ89D0NRR2%26tag%3Dws%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB000KJX3A0 I can...
0
7455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5319
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3437
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1867
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
692
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.