urllib2.urlopen issue

D

David

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')>


I think this is caused by the embedded "v_url=..." in the url.
Anybody
knows how to fix this? By the way, this code works well if I change
the value of url to something like "www.yahoo.com" or
"www.google.com".


Thanks so much.
 
C

Chris Rebert

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.

Cheers,
Chris
 
D

David

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.

Cheers,
Chris
--http://blog.rebertia.com- Hide quoted text -

- Show quoted text -

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?
 
M

Miles Kaufmann

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
 

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

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top