strange problems with urllib2

J

jdonnell

When I run this code on windows it runs quickly (about a second per
image) but when I run it on linux it runs very very slowly (10+ seconds
per image). Is this a bug or am I missing something? On windows I tried
2.4.2 and 2.4.1 on linux i'm running 2.4.1

print 'starting'
f =
urllib2.urlopen('http://site.heavenlytreasures.com/images/e6115.jpg')
outfile = open('e6115.jpg', 'wb')
outfile.write(f.read())
outfile.close()
f.close()
print 'finished'
 
T

Tim Roberts

jdonnell said:
When I run this code on windows it runs quickly (about a second per
image) but when I run it on linux it runs very very slowly (10+ seconds
per image). Is this a bug or am I missing something? On windows I tried
2.4.2 and 2.4.1 on linux i'm running 2.4.1

That kind of thing is often caused by DNS problems. Are you running named
on your Linux machine? Have you double-checked that the named
configuration and /etc/resolv.conf is correct?

How long does it take for you to do this:
wget http://site.heavenlytreasures.com/images/e6115.jpg
 
C

Cousin Stanley

When I run this code on windows it runs quickly
(about a second per image) but when I run it on linux
it runs very very slowly (10+ seconds per image).
....

jdonnell ....

I'm running a 1999 vintage 250 MHz Compaq
with Debian Gnu/Linux & Python 2.3.5 ....

The following version of your code
worked very well here ....

# ---------------------------------------------------
#!/usr/bin/env python

'''
NewsGroup .... comp.lang.python
Date ......... 2005-10-26
Posted_By .... jdonnell
Edited_By .... Stanley C. Kitching
'''

import sys
import time
import urllib2

this_module = sys.argv[ 0 ]

beg = time.time()

f = urllib2.urlopen( 'http://site.heavenlytreasures.com/images/e6115.jpg' )

outfile = open( 'e6115.jpg' , 'wb' )

outfile.write( f.read() )

outfile.close()

f.close()

end = time.time()

dt = end - beg

print
print ' %s' % this_module
print
print ' Image saved .... %.4f Seconds ' % dt
print

# ---------------------------------------------------


sk@cpq1 : ~/python $ ./urllib2_image_get.py

./urllib2_image_get.py

Image saved .... 0.3973 Seconds
 
J

jdonnell

I haven't checked them, but will do it now. However, I don't have
problems with anything but python. I can download that image in less
than a second with wget or in my browser. I know that I had ipv6
problems before. I had to turn it off because of my nat router so I'll
look into that sort of thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,269
Messages
2,571,338
Members
48,026
Latest member
DannieKeeg

Latest Threads

Top