473,787 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Non-blocking read() in httplib?

I have the following problem with HTTPResponse:

import httplib #, select
....
connection = httplib.HTTPCon nection(host)
connection.conn ect()
connection.requ est('GET', url)
response = connection.getr esponse()
# print response.status , response.reason gives '200 OK'
# ready = select.select([response],[],[], 5.0) # no fileno() method
# signal.alarm(5) # not on Windows
# ...
data=response.r ead() # this sometimes blocks
connection.clos e()

Sometimes the read() call blocks forever for no obvious reason
(response.statu s is OK); it even cannot be interrupted from the keyboard
(on Windows).

I would like to defend against this by throwing an exception when the
read() lasts too long. But I cannot use select.select() , because
HTTPResponse has no fileno() method. Neither can I use signal.alarm(),
as it is for Unixes only.

Is there any other way to break read() or make it non-blocking?

Regards,
Marcin

Jul 18 '05 #1
4 3417
Marcin Ciura wrote:
I have the following problem with HTTPResponse:

import httplib #, select
...
connection = httplib.HTTPCon nection(host)
connection.conn ect()
connection.requ est('GET', url)
response = connection.getr esponse()
# print response.status , response.reason gives '200 OK'
# ready = select.select([response],[],[], 5.0) # no fileno() method
# signal.alarm(5) # not on Windows
# ...
data=response.r ead() # this sometimes blocks
connection.clos e()

Sometimes the read() call blocks forever for no obvious reason
(response.statu s is OK); it even cannot be interrupted from the keyboard
(on Windows).

I would like to defend against this by throwing an exception when the
read() lasts too long. But I cannot use select.select() , because
HTTPResponse has no fileno() method. Neither can I use signal.alarm(),
as it is for Unixes only.

Is there any other way to break read() or make it non-blocking?

I'm using timeoutsocket.p y which allows you to globally specify a
timeout for all sockets. Used signal.alarm before, which caused more
problems than it solved...
Jul 18 '05 #2
Marcin Ciura <ci*********@ze us.polsl.gliwic e.pl> pisze:
Sometimes the read() call blocks forever for no obvious reason
(response.statu s is OK); it even cannot be interrupted from the keyboard
(on Windows).

I would like to defend against this by throwing an exception when the
read() lasts too long. But I cannot use select.select() , because
HTTPResponse has no fileno() method. Neither can I use signal.alarm(),
as it is for Unixes only.

Is there any other way to break read() or make it non-blocking?


You can try to write your own HTTP client module, that uses
asyncore/asynchat. You may find a minimal implementation in my project's
CVS (URL in signature). It is based on code found in "EffNews Part 1:
Fetching RSS Files" tutorial (http://www.effbot.org/zone/effnews-1.htm).

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #3
Marcin Ciura <ci*********@ze us.polsl.gliwic e.pl> writes:
I would like to defend against this by throwing an exception when the
read() lasts too long. But I cannot use select.select() , because
HTTPResponse has no fileno() method. Neither can I use signal.alarm(),
as it is for Unixes only.

Is there any other way to break read() or make it non-blocking?


I think I'd reach down into the response object and get the fileno.
From httplib.py:

class HTTPResponse:
# ...
def __init__(self, sock, debuglevel=0, strict=0):
self.fp = sock.makefile(' rb', 0)
self.debuglevel = debuglevel
self.strict = strict

so maybe you can get the fileno from response.fp.
Jul 18 '05 #4
Jarek Zgoda <jz****@gazeta. usun.pl> writes:
[...]
You can try to write your own HTTP client module, that uses
asyncore/asynchat. You may find a minimal implementation in my project's
CVS (URL in signature). It is based on code found in "EffNews Part 1:
Fetching RSS Files" tutorial (http://www.effbot.org/zone/effnews-1.htm).


There used to be one called asynchttp.py. There was also an
asyncurl.py. I think both are likely still around somewhere, but not
maintained.
John
Jul 18 '05 #5

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

Similar topics

0
1679
by: hitectahir | last post by:
Hi, I have been using a remote data server named Clarens which runs on top of the Apache web server and communicates through xmlrpc on Redhat Linux 7.3. It has been working fine for about a month, but today it has started giving some error in httplib.py. The complete traceback is given below: Traceback (most recent call last): File "clarensclient.py", line 2, in ?
0
1208
by: Carl-Johan Kjellander | last post by:
I have a problem. I want to use httplib to a site that has both IPv4 and IPv6 connectivity, hence it has both A and AAAA records. Is there a way to force httplib to use IPv6 only, or to at least try IPv6 before IPv4? As it is now, httplib always takes the IPv4 address first. If there isn't a way to do this, i.e. httplib always connects to the IPv4 address first, and there is now way to change that, who do I talk to about adding a...
2
2179
by: Glauco | last post by:
I'm using a library based on httplib. Recently i've done a conversion for use of https with a key and certificate file. This goes perfectly :-) . Now, the problem is passing throw an http_proxy. It seems because httplib (based on socket.py) try to autenticate on the proxy. I'm only with this problem ? it's impossible :-|
2
15937
by: scummer | last post by:
Hi, I am having a problem with the httplib HTTPConnection object. While I can easily send requests that don't have any payload (ie. "get"), I encounter issues if I want to post xml data. If you look at the class below, when req == 'getFreeBusyInfo' all functions perfectly, but when req == 'conflictRequest' I run into problems of the nature "400 Bad Request". As you will notice, I also tried the shorter HTTPConnection instance method...
0
1903
by: Milos Prudek | last post by:
How can I set httplib timeout for httplib.request() ? httplib.request timeouts after 3:10 with "socket" timeout error message. I found socket.settimeout() and I believe there is a way to add ".settimeout()" function to httplib without hacking httplib source. Is it possible? --
3
15446
by: alastair | last post by:
Hi, I'm attempting to test out some functionality of the Apache http server. What I'd like to do is send a file to the server - eg. a text file or binary file (I will be testing gzipped transfers eventually ....). At the moment I can test out sending a set of parameters to the server, and using mod_python, I have a python script which displays these values.
4
3712
by: michaelparkin | last post by:
Hi, Sorry to post what might seem like a trivial problem here, but its driving me mad! I have a simple https client that uses httplib to post data to a web server. When I post over http & https using curl the data is recieved by the web server with no problems.
2
10764
by: spamsink42 | last post by:
this code h=httplib.HTTPConnection('euronext.com') h.request('GET', 'http://www.euronext.com/home/0,3766,1732,00.html') fails with this message File "httplib.py", line 532, in connect socket.SOCK_STREAM):
6
2408
by: Haakon Riiser | last post by:
After a long debugging session while scripting my webmail, I believe I have traced the problem to the way httplib sends POST requests. I have compared tcpdump listings from Python 2.4.3 and 2.5.0's httplib (via urllib/urllib2), Perl's LWP::UserAgent 2.033 and Firefox 2.0. Only Python sends the request in such a way that the mailserver closes the connection before I get any data from the POST request (immediate FIN packet after the POST...
11
12336
by: Phoe6 | last post by:
Hi, The following piece of code works properly when my proxy password contains characters etc. But when my proxy password contained something like '|\/|' , the httplib incorrectly indentified it as separator. How do I resolve this issue. <code> # Proxy Address PROXY_IP = "1.1.9.8:80"
0
10363
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...
0
10169
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.