473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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_html(self.response)
File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py",
line 464, in _parse_html
for token in p.tags(*(self.urltags.keys()+["base"])):
File "/usr/lib/python2.3/site-packages/pullparser.py", line 90, in
iter_until_exception
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_starttag(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("malformed start tag")
File "/usr/lib/python2.3/HTMLParser.py", line 115, in error
raise HTMLParseError(message, self.getpos())
HTMLParser.HTMLParseError: 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 3573
Erling Ringen Elvsrud <er*******@killozapHALLO.com.invalid> writes:
[...]
HTMLParser.HTMLParseError: 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.HTMLParser
everywhere, and not use HTMLParser.HTMLParser. 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
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...
0
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...
4
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...
1
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...
2
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...
1
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 =...
3
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...
8
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:...
2
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: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.