PDA

View Full Version : Python urllib2 problem: Name or service not known



Iskendar
Feb 27th 2012, 07:43 PM
Hi all,

Some time ago I've written some python code to read video data off an IP camera connected via a router to a laptop. Now I try to run this code on a different laptop and router combination, but now I can't access the camera.
Some minimal example code:


import urllib2

url = urllib2.urlopen("http://192.168.1.3/-wvhttp-01-/image.cgi")

This fails and returns the error:

<urlopen error [Errno -2] Name or service not known

When I check further, I cannot access any url via urllib2.urlopen, not the camera nor the router nor localhost. Pinging them poses no problem though, and I can access the video feed and the router admin page in firefox without any issues.
Searching for the problem turned up this discussion (http://forums.gentoo.org/viewtopic-t-556507.html) on the gentoo forums, which didn't provide any solution but did hint that it might be a system-related problem rather than a coding problem.
I run kubuntu 11.10 on the laptop, the router is not connected to the internet and serves as dhcp server for both the laptop and the camera.

Iskendar
Feb 28th 2012, 09:34 AM
Never mind it's a proxy problem. I disabled http_proxy in .bashrc for this, but apparently it was also set in /etc/bash.bashrc and I didn't check for that.

That did leave me with the problem how I could get my code to work with the proxy enabled. But I found that one too, just put


import os
os.environ['http_proxy']=''

before importing urllib2.