On Jun 24, 2009, at 2:59 PM, David wrote:
On Jun 24, 11:27 am, Chris Rebert wrote:
On Wed, Jun 24, 2009 at 10:50 AM, David wrote:
hello,

I have a url that is "http://query.directrdr.com/ptrack?
pid=225&v_url=http://
www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said".
If I open it on a browser, I can get its contents without any
problem.
However, if I use following code,

import urllib2

url = 'http://query.directrdr.com/ptrack?pid=225&v_url=http://
www.plentyoffish.com&keyword=flowers&feed=1&ip=12.2.2.2&said=$said'

xml = urllib2.urlopen(url).read()

then I get an exception of

 File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open
   raise URLError(err)
urllib2.URLError: <urlopen error (-2, 'Name or service not known')>

Unable to reproduce with either urllib or urllib2's urlopen(). I get
some XML back without error both ways. Using Python 2.6.2 on Mac OS X.


Thanks Aahz. And thanks Chris. The XML content is what I am looking
for. I use Python 2.5. Maybe I should update to 2.6.2? Python version
problem?

No, it also works for me on Python 2.5.1. A wild guess: does this code work?

import socket
socket.gethostbyname(socket.gethostname())

If it throws a similar exception (Name or service not known), the root problem may be a misconfiguration in your /etc/hosts or /etc/ resolv.conf files.

-Miles

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to