By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,655 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

strange problems with urllib2

P: n/a
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'

Oct 26 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"jdonnell" <ja********@gmail.com> wrote:

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
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 27 '05 #2

P: n/a

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
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Oct 27 '05 #3

P: n/a
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.

Oct 27 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.