473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

urllib2 timeout??

Python2.3 on Redhat Linux 8.0 here is the code.

import urllib2

import ClientCookie

request =
urllib2.Request ("http://fantasygames.sp ortingnews.com/crs/home_check_reg. htm
l",data='userna me=penngray1&pa ssword=testpwd' )

response = ClientCookie.ur lopen(request)

#return response.info()

request2
=urllib2.Reques t("http://fantasygames.sp ortingnews.com/baseball/fullseason/u
ltimate/game/frozen_roster.h tml?user_id=620 8")

resp2 = ClientCookie.ur lopen(request2)

return resp2.read()



The ClientCookie is a 3rd party software that handles the Set-cookie stuff
on the client for me. This allows me to login into a site then access other
webpages from that site that need cookies set. The problem is that 50% of
the time it works and 50% of the time it fails. I assume this problem is a
time out problem

Is there a time out problem here, why is the connection so slow in the first
place. Is it my unix server?

Here is the error when it fails.

Traceback (most recent call last):

File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch
result = object(req)

File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line 136,
in handler
result = util.apply_fs_d ata(object, req.form, req=req)

File "/usr/lib/python2.3/site-packages/mod_python/util.py", line 361, in
apply_fs_data
return object(**args)

File "/usr/local/apach2/fantasy/TSN/htmlRead.py", line 31, in getwebpage
response = ClientCookie.ur lopen(request)

File "/usr/lib/python2.3/site-packages/ClientCookie/_urllib2_suppor t.py",
line 829, in urlopen
return _opener.open(ur l, data)

File "/usr/lib/python2.3/site-packages/ClientCookie/_urllib2_suppor t.py",
line 520, in open
response = urllib2.OpenerD irector.open(se lf, req, data)

File "/var/tmp/python2.3-2.3.3-root/usr/lib/python2.3/urllib2.py", line
326, in open
'_open', req)

File "/var/tmp/python2.3-2.3.3-root/usr/lib/python2.3/urllib2.py", line
306, in _call_chain
result = func(*args)

File "/usr/lib/python2.3/site-packages/ClientCookie/_urllib2_suppor t.py",
line 754, in http_open
return self.do_open(ht tplib.HTTP, req)

File "/usr/lib/python2.3/site-packages/ClientCookie/_urllib2_suppor t.py",
line 612, in do_open
raise URLError(err)

URLError:


Thanks in advance

Doug
Jul 18 '05 #1
1 5684
"Doug Gray" <dg***@coldstor age.com> writes:
[...]
request =
urllib2.Request ("http://fantasygames.sp ortingnews.com/crs/home_check_reg. htm
l",data='userna me=penngray1&pa ssword=testpwd' )

response = ClientCookie.ur lopen(request)

#return response.info()

request2
=urllib2.Reques t("http://fantasygames.sp ortingnews.com/baseball/fullseason/u
ltimate/game/frozen_roster.h tml?user_id=620 8")

resp2 = ClientCookie.ur lopen(request2)

return resp2.read()
Looks fine. No need to have an explicit Request object every time,
though: just pass the URL to urlopen.

The ClientCookie is a 3rd party software that handles the Set-cookie stuff
on the client for me. This allows me to login into a site then access other
webpages from that site that need cookies set. The problem is that 50% of
the time it works and 50% of the time it fails. I assume this problem is a
time out problem
As they used to say in Parliament: I refer the Honourable Gentleman to
the answer I gave some moments ago (in a thread with subject "urllib2
request blocks"). I'm not sure it's a timeout problem, though.

Is there a time out problem here, why is the connection so slow in the first
place. Is it my unix server?
Looks like some relatively low-level problem (some socket error that
httplib's not catching). Not sure precisely what, though.

[...] Traceback (most recent call last): [...] File "/usr/lib/python2.3/site-packages/ClientCookie/_urllib2_suppor t.py",
line 612, in do_open
raise URLError(err)

URLError:


I'm not sure why you're not getting a more informative error message
here. URLError here is wrapping a socket.error. Try catching it and
printing the socket error directly:

try:
response = urllib2.OpenerD irector.open(se lf, req, data)
except urllib2.URLErro r, e:
print "e.reason", e.reason
John
Jul 18 '05 #2

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

Similar topics

2
2588
by: Derek Fountain | last post by:
I just tried this: >>> import urllib2 >>> urllib2.urlopen( "https://passenger.ssc.com/~dmarti/contrib-faq/" ) It sits forever. Loading that URL in a normal browser gets me a popup asking about server certificate authenticity, which presumably is what urllib2 is blocking at. How can I prepare my code for this eventuality and ensure it doesn't block?
2
1808
by: Gerard C Blais | last post by:
I'm trying to get a page from a slow server. and i'm timing out. I've tried socket.setdefaulttimeout9300), and urllib2.socket.setdefaulttimeout(300), and urllib2.socket.setdefauttimeout(300.0),
3
2014
by: EP | last post by:
Hello patient and tolerant Pythonistas, Iterating through a long list of arbitrary (and possibly syntactically flawed) urls with a urllib2 pinging function I get a hang up. No exception is raised, however (according to Windows Task Manager) python.exe stops using any CPU time, neither increasing nor decreasing the memory it uses, and thescript does not progress (permanently stalled, it seems). As an example, the below function has been...
0
1195
by: Dan M | last post by:
I'm writing a system monitor script that needs to load web pages. I'm using urllib2.urlopen to get the pages, and I'm attempting to set the timeout value using socket.defaulttimeout. Specifically, I'm calling socket.defaultttimeout(10), then calling urllib2.urlopen to fetch a web page that never gets delivered. My code waits about 30 seconds before terminating. I am about to add threading to my app so that delays on a few servers...
1
2884
by: Astan Chee | last post by:
Hi again, According to https://demo.launchpad.net/products/python/+bug/56872 or more specifically, the example of its working code: http://librarian.demo.launchpad.net/3507227/urllib2_proxy_auth.py I can use urllib2 via proxy to access a https site(specifically hooking it up to libgmail). The problem is that the proxy that is accessible to me is http/port8080 only. Is it possible to use urllib2 with this proxy to access a https site?...
4
2585
by: dumbkiwi | last post by:
I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with.
2
12386
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)
3
5759
by: konstantin | last post by:
Hi, I wonder if there is a safe way to download page with urllib2. I've constructed following method to catch all possible exceptions. def retrieve(url): user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = {'User-Agent':user_agent} request = urllib2.Request(url, headers=headers) try:
1
3078
by: Gilles Ganault | last post by:
Hello I'm using urllib2 to download web pages. The strange thing in the code below, is that it seems like urllib2.urlopen retries indefinitely by itself instead of raising an exception: ===== timeout = 30 socket.setdefaulttimeout(timeout)
0
8323
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
8838
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
8513
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
8613
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
7351
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
5638
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
4173
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...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
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.