473,602 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

urllib problem (maybe bugs?)

Hi,

I'm trying to fill the form on page
http://www.cbs.dtu.dk/services/TMHMM/ using urllib.

There are two peculiarities. First of all, I am filling in incorrect
key/value pairs in the parameters on purpose because that's the only
way I can get it to work.. For "version" I am suppose to leave it
unchecked, having value of empty string. And for name "outform" I am
suppose to assign it a value of "-short". Instead, I left out
"outform" all together and fill in "-short" for version. I discovered
the method my accident.

After I've done that it works fine for small SEQ values. Then, when I
try to send large amount of data (1.4MB), it fails miserably with
AttributeError exception.

I highly suspect the two problems I have are the result of some bugs
in the urllib module. Any suggestions?

This is my code:

=============== =============== =============== ===============
fd = open('secretory 0_1.txt', 'r')
txt = fd.read()
fd.close()

params = urllib.urlencod e({'SEQ': txt, 'configfile':
'/usr/opt/www/pub/CBS/services/TMHMM-2.0/TMHMM2.cf', 'version':
'-short'})
f = urllib.urlopen( "http://www.cbs.dtu.dk/cgi-bin/nph-webface", params)
data = f.read()

start = data.find('foll ow <a href="h') + 16
end = data.find('">Th is link</a>')
secondurl = data[start:end]

f = urllib.urlopen( secondurl)
print f.read()
=============== =============== =============== ===============
The value pairs I am suppose to fill in are:

SEQ => some sequence here
configfile => '/usr/opt/www/pub/CBS/services/TMHMM-2.0/TMHMM2.cf'
version => ''
outform => '-short'
The exception I get when sending secretory0_1.tx t is:

C:\Documents and Settings\thw\®à *±>python testhttp.py
Traceback (most recent call last):
File "testhttp.p y", line 11, in ?
f = urllib.urlopen( "http://www.cbs.dtu.dk/cgi-bin/nph-webface", params)
File "C:\Python24\li b\urllib.py", line 79, in urlopen
return opener.open(url , data)
File "C:\Python24\li b\urllib.py", line 182, in open
return getattr(self, name)(url, data)
File "C:\Python24\li b\urllib.py", line 307, in open_http
return self.http_error (url, fp, errcode, errmsg, headers, data)
File "C:\Python24\li b\urllib.py", line 322, in http_error
return self.http_error _default(url, fp, errcode, errmsg, headers)
File "C:\Python24\li b\urllib.py", line 550, in http_error_defa ult
return addinfourl(fp, headers, "http:" + url)
File "C:\Python24\li b\urllib.py", line 836, in __init__
addbase.__init_ _(self, fp)
File "C:\Python24\li b\urllib.py", line 786, in __init__
self.read = self.fp.read
AttributeError: 'NoneType' object has no attribute 'read'

Timothy
Jul 18 '05 #1
1 2063
Timothy Wu <2h*****@gmail. com> wrote:

I'm trying to fill the form on page
http://www.cbs.dtu.dk/services/TMHMM/ using urllib.

There are two peculiarities. First of all, I am filling in incorrect
key/value pairs in the parameters on purpose because that's the only
way I can get it to work.. For "version" I am suppose to leave it
unchecked, having value of empty string. And for name "outform" I am
suppose to assign it a value of "-short". Instead, I left out
"outform" all together and fill in "-short" for version. I discovered
the method my accident.

After I've done that it works fine for small SEQ values. Then, when I
try to send large amount of data (1.4MB), it fails miserably with
AttributeErr or exception.

I highly suspect the two problems I have are the result of some bugs
in the urllib module. Any suggestions?


The <form> on that page wants multipart/form-data encoding, where each
parameter is embedded in a separate MIME section. That is common with very
large data, and is _required_ when the form includes a file upload. urllib
doesn't do that. It always sends plain old
application/x-www-form-urlencoded data.

I think you're going to have to roll your own sender.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2

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

Similar topics

4
5178
by: Gary Feldman | last post by:
I think I've found a deficiency in the design of urllib related to https. In order to complete an https connection, it appears that URLOpener and hence FancyURLOpener require the key and cert files. Or at least, it's not clear from the description of socket.ssl what it does if they're omitted. However, urlopen has no way to specify such things. Nor should it - for typical uses, a person simply trying to retrieve data from an ssl site...
3
4460
by: Michael | last post by:
How do you change the user agent reported by urllib? I need to access a resource that rejects anything but IE.
3
2454
by: Haim Ashkenazi | last post by:
Hi I'm writing a script that uses urllib on win98. until now I used python 2.3.x (x < 4) and it worked ok. I re-installed windows and installed python 2.3.4 and now I get an error when trying to open a url "no host given": Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 Type "copyright", "credits" or "license()" for more information.
7
2324
by: Stuart McGraw | last post by:
I just spent a $*#@!*&^&% hour registering at ^$#@#%^ Sourceforce and trying to submit a Python bug report but it still won't let me. I give up. Maybe someone who cares will see this post, or maybe it will save time for someone else who runs into this problem... ================================================ Environment: - Microsoft Windows 2000 Pro
0
2440
by: Ali.Sabil | last post by:
hello all, I just maybe hit a bug in both urllib and urllib2, actually urllib doesn't support proxy authentication, and if you setup the http_proxy env var to http_proxy=http://user:passwd@host:port/ and https_proxy=$http_proxy i get a traceback : Traceback (most recent call last): File "test_urllib.py", line 2, in ? urllib.urlopen("https://sf.net/")
1
496
by: evanpmeth | last post by:
I have tried multiple ways of posting information to a website and have failed. I have seen this problem on other forums can someone explain or point me to information on how POST works through urllib an different broweser (what is the difference). my first attempt was out of the docs: Code: import httplib, urllib params = urllib.urlencode({'email' : 'a@a.com',
4
6133
by: John Nagle | last post by:
There's no way to set a timeout if you use "urllib" to open a URL. "HTTP", which "urllib" uses, supports this, but the functionality is lost at the "urllib" level. It's not available via "class URLopener" or "FancyURLopener", either. There is a non-thread-safe workaround from 2003 at http://mail.python.org/pipermail/python-bugs-list/2003-September/020405.html
2
1651
by: shirish | last post by:
Hi all, Before I start, please know that I'm no developer, just a user. This is also a cross-post as I have tried to post the same at python- bugs mailing list, just don't know if it gets in or not. We have a bug-reporting system in ubuntu called apport. Apparently apport uses a python library called urllib. As of now, apport does a bouncing bar while uploading which doesn't give the user idea as to how much is being uploaded. Refer...
5
7682
by: John Nagle | last post by:
I thought I had all the timeout problems with urllib worked around, but no. socket.setdefaulttimeout is useful, but not always effective. I'm setting that to 15 seconds. If the host end won't open the connection within 15 seconds, urllib times out. But if the host end opens the connection, then never sends anything, urllib waits for many minutes before timing out. Any idea how to deal with this? And don't just say "use urllib2"...
0
7993
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.