Update from V115 to V117 Breaks Python

Hi,
After I upgrade from V115 to V117, I realize V117 breaks my python script with urllib library.
When I re-write the V115 image, the python is working again.
Not sure is this a bug or something else?

update:
my apt-get update also breaks after update to V117

Hi BBmak,

When you say “breaks your python script and apt-get update”, please could you provide us with more information. Either a screenshot of the error/issue when it occurs, or a copy and paste over SSH.

With the requested information above, we should be able to assist you :slight_smile:

Sure, Thank you for the reply. Here is the output of one of the scripts that I am using to update the noip ddns.

Traceback (most recent call last):
File “noip.py”, line 7, in
web_page = urllib.urlopen("> http://iptools.bizhat.com/ipv4.php> ")
File “/usr/lib/python2.7/urllib.py”, line 87, in urlopen
return opener.open(url)
File “/usr/lib/python2.7/urllib.py”, line 213, in open
return getattr(self, name)(url)
File “/usr/lib/python2.7/urllib.py”, line 350, in open_http
h.endheaders(data)
File “/usr/lib/python2.7/httplib.py”, line 997, in endheaders
self._send_output(message_body)
File “/usr/lib/python2.7/httplib.py”, line 850, in _send_output
self.send(msg)
File “/usr/lib/python2.7/httplib.py”, line 812, in send
self.connect()
File “/usr/lib/python2.7/httplib.py”, line 793, in connect
self.timeout, self.source_address)
File “/usr/lib/python2.7/socket.py”, line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno -2] Name or service not known

Another script using urllib

Traceback (most recent call last):
File “afraid.py”, line 20, in
newip = urllib2.urlopen("> http://ip.dnsexit.com/> ").read().strip()
File “/usr/lib/python2.7/urllib2.py”, line 154, in urlopen
return opener.open(url, data, timeout)
File “/usr/lib/python2.7/urllib2.py”, line 431, in open
response = self._open(req, data)
File “/usr/lib/python2.7/urllib2.py”, line 449, in _open
‘_open’, req)
File “/usr/lib/python2.7/urllib2.py”, line 409, in _call_chain
result = func(*args)
File “/usr/lib/python2.7/urllib2.py”, line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File “/usr/lib/python2.7/urllib2.py”, line 1197, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>

Might be related to the recent proxy support in DietPi.

As per this page, please try:

Ok, doing os.environ[‘http_proxy’]=‘’ before importing urllib2 seems
to do the trick for that.

Failing that, try running the script with python 3:

python3 myscript.py

You might need to:

apt-get install python3

I tried your suggestions, python3 seems working, but I have to change a lot of my codes in order to make my scripts work in python3.

When I use os.environ[‘http_proxy’]=‘’ before importing urllib2, i got the same output as previous.

using V117 also break my apt-get update. It throws me an error as well.

Strange. Is it possible the urllib2 library you have is only python3 compatible?

The apt-get update error, could you paste the error or screenshot it please? There may be a issue with a repo that is causing this. Could even be linked to your python issue if packages were installed from various repos.

Regarding: https://dietpi.com/forum/t/dietpi-v117/340/1

Can you paste the results of the following please:

cat /etc/apt/sources.list

Please see image when I perform apt-get update after I updated to V117 from V115.

Update: Just realized that ping google.com is not working too, and ping 8.8.8.8 is working.

Thanks.

Looks like your DNS isnt working correctly.

Can you paste the contents of this file please:

cat /etc/network/interfaces

Please remove any WiFi passwords if you have set them, prior to posting.

And:

route

cat /etc/network/interfaces

#/etc/network/interfaces

Local

#auto lo
#iface lo inet loopback

Ethernet

allow-hotplug eth0
iface eth0 inet static
metric 0
address 192.168.0.70
netmask 255.255.255.0
gateway 192.168.0.2
dns-nameservers 8.8.8.8 8.8.4.4

Wifi

#allow-hotplug wlan0
#iface wlan0 inet static
metric 1
#address 192.168.0.70
#netmask 255.255.255.0
#gateway 192.168.0.2
#wireless-essid FuzonWifi
#wireless-key abcde12345
#wireless-mode Managed
#wireless-power off
#wpa-ssid FuzonWifi
#wpa-psk abcde12345
#dns-nameservers 8.8.8.8 8.8.4.4

route

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.2 0.0.0.0 UG 0 0 0 eth0
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0

In /etc/network/interfaces, you need to enable the following lines:

auto lo
iface lo inet loopback

Reboot then try again.

Have you manually commented out these entries? If so doing so may break dietpi-config > Networking adapters.

# Wifi
#allow-hotplug wlan0
#iface wlan0 inet static
metric 1
#address 192.168.0.70
#netmask 255.255.255.0
#gateway 192.168.0.2
#wireless-essid FuzonWifi
#wireless-key abcde12345
#wireless-mode Managed
#wireless-power off
#wpa-ssid FuzonWifi
#wpa-psk abcde12345
#dns-nameservers 8.8.8.8 8.8.4.4

A disabled WiFi adapter should look like this. This will prevent dietpi-config from obtaining unexpected data:

# Wifi
#allow-hotplug wlan0
iface wlan0 inet dhcp
metric 1
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
wireless-essid Not_Set
wireless-key Not_Set
wireless-mode Managed
wireless-power off
wpa-ssid Not_Set
wpa-psk Not_Set
#dns-nameservers 8.8.8.8 8.8.4.4

Thank you. Following you advice, it works now.

one more question, do I need to comment the #dns-nameservers 8.8.8.8 8.8.4.4 If I do not want the wifi? In your quote, you did put a comment there.

Hi bbmak,

please have a look:

root@oDroid-C1-TEST:~# cat /etc/network/interfaces



#/etc/network/interfaces
#Please use DietPi-Config to modify network settings.

# Local
auto lo
iface lo inet loopback

# Ethernet
allow-hotplug eth1
....

will say, if you want to alter your network settings, please use menu " 7 Network Options: Adapters " in:

root@oDroid-C1-TEST:~# dietpi-config

160514-0001.gif
In this menu you can as well disable WiFi adapter:
160514-0003.gif

Correct is:

# Wifi
 . . .
#dns-nameservers 8.8.8.8 8.8.4.4



" dietpi-config " did this. Where is no need, to edit " /etc/network/interfaces " manually, to disable WiFi adapter.
But if you edit the file manually before, you have to set it now “once” by hand, so dietpi-config can work correct.

BWT: - to have one, both, fallback network adapters working at the same time, having two different gateways or subnets, working infrastructure mod, static IP or dhcp, with WiFi HotSpot, with PiHole installed and so on, is a new feature in v116/ v117: https://github.com/Fourdee/DietPi/issues/273#issuecomment-210905921

And yes, it was a long and stony journey for @Fourdee to get it on work. :smiley:

Thanks guys. Really appreciate your helps.

Hi,

do now “dietpi-config” work for you? Can you change the network settings of your adapter?

Does internet connection work after changing any settings?

Yes, after following Fourdee’s instruction, it works. I changed the /etc/network/interfaces back to the default setting of dietpi.
dietpi-config works, but I do not have wifi, so no option for me to disable it.
Yes, I am able to change my network setting.
Internet works fine. I can ping google.com now.

I plan to upgrade to V118 today. Hopefully no problem. Will make back up image for current setting, in case of failed.

Just Update to V118. I don’t experience any problem so far.

here is my /etc/networks/interfaces after I upgrade.

Local

auto lo
iface lo inet loopback

Ethernet

allow-hotplug eth0
iface eth0 inet static
metric 0
address 192.168.0.70
netmask 255.255.255.0
gateway 192.168.0.2
dns-nameservers 8.8.8.8 8.8.4.4

Wifi

#allow-hotplug wlan0
iface wlan0 inet static
metric 1
address 192.168.0.70
netmask 255.255.255.0
gateway 192.168.0.2
wireless-essid FuzonWifi
wireless-key abcde12345
wireless-mode Managed
wireless-power off
wpa-ssid FuzonWifi
wpa-psk abcde12345
#dns-nameservers 8.8.8.8 8.8.4.4

Looks good :slight_smile:, and, wlan0 is correctly disabled in this config.