Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Unable to run a Python script

Wed Aug 26, 2020 2:33 pm

I have a Python script I want to run 24/7 on my Raspberry Pi, and I have checked it works, and I know that it is correct. However. while the script will run fine on Windows for extended periods of time, it seems that it doesn't want to run on Linux, as when I run it, it works for a while then gives up, throwing an error telling me that the name couldn't be resolved. My internet is fine on my Windows machine, so I don't think it's a problem at the network level. Can anyone help me with this? I'd like to be able to use my Pi as a box to run my scripts off of, but if they keep stopping, I'm not going to be able to do so.

dbrion06
Posts: 197
Joined: Tue May 28, 2019 11:57 am

Re: Unable to run a Python script

Wed Aug 26, 2020 2:57 pm

Excuse me, but very few people have telescopic eyes.
you can post parts of your code (find out which parts are suspect) between [ c o d e ] and [ / c o d e ] -remove whitespace to delimit, or the 5th button from the left in this very menu...

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Wed Aug 26, 2020 3:17 pm

That's the thing. I have two scripts, one which runs on Linux and one on Windows. The only difference between the two is the location where the files are saved. One is a Linux path and the other is a Windows path. 99.99% of the two pieces of code are identical.

pcmanbob
Posts: 10117
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Unable to run a Python script

Wed Aug 26, 2020 3:17 pm

So if your program errors with name can't be resolved , then it's almost certain that you pi has lost its network connection or the connection to the DNS.

You need to tell us a lot more detail before any one can help you.

So for starters.

Which pi
How is it connected to the network
What type of network is it connected to
How long before you program error
When you program error can you still ping the pi from another computer on the network
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Wed Aug 26, 2020 3:22 pm

Which Pi?
The model is a Raspberry Pi 4 4GB

How is it connected to the network
It is connected to the network via an Ethernet cable which is plugged into a WiFi extender.

What type of network is it connected to
It is connected to Ethernet

How long before you program error
The length of time between errors can vary.

When you program error can you still ping the pi from another computer on the network
Yes, I can still ping the Pi after the program errors.

geektechstuff.com
Posts: 42
Joined: Sat Mar 02, 2019 8:08 pm
Contact: Website

Re: Unable to run a Python script

Wed Aug 26, 2020 4:14 pm

It does read like the Pi may be losing connectivity - could you leave a ping command running and see if any packets drop?

Also, can you post the Python script on here using the Code option?
www.geektechstuff.com

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Wed Aug 26, 2020 5:02 pm

Here is the output of my ping command:

Code: Select all

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=61.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=115 time=41.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=115 time=54.10 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=115 time=19.7 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 19.652/44.222/61.202/15.946 ms
and here is my code:

Code: Select all

import praw
import requests
import random
import string
import time
import hashlib

from pathlib import Path
import os
import os.path
from os import path

# Creating a new Reddit instance to access the API
reddit = praw.Reddit('reddit_bot')

'''
Allows for multiple subreddits to be entered. Enter each
subreddit followed by the enter key
'''
def exec(n):
    subreddits = n.read()
    print("Monitoring subreddits...")
    return subreddits.replace("\n", "+")

'''
For this piece of code to function properly, a folder must be created
inside the same directory as the script to store the files in, as the
location that is used for output is a relative path
'''
def download_img(url):
    r = requests.get(url)
    filename = hashlib.md5(r.content).hexdigest()
    root = Path('D:/pregs')
    location = root/f"{filename}.jpg" 
    #Path.cwd()/f"output_pics"/f"{filename}.jpg"

    # Check if the destination folder exists, and create it if not
    if not os.path.exists(root):
        os.makedirs(root)

    '''
    Send a request to the image URL that has been grabbed using the API
    If the filename that is to be assigned to a file does not already exist,
    create the file with that name, otherwise, skip that filename and generate
    a new one.
    '''
    if path.exists(location) == False:
        r = requests.get(url)
        with open(location, 'wb') as f:
            f.write(r.content)
            f.close()

def create_url_stream(subreddit):
    count = 0
    for sub in subreddit.stream.submissions():
        if str(sub.url).endswith(('.jpg', '.jpeg', '.png')):
            download_img(sub.url)        
            print(f"\rIteration {count}...", end="")
            count += 1
        # After each image download, sleep for 5 seconds
        time.sleep(5)

def main():
    n = open("inputs.txt")
    subreddit = reddit.subreddit(exec(n))
    create_url_stream(subreddit)

if __name__ == "__main__":
    main()
Apologies for the length.

User avatar
jahboater
Posts: 6274
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Unable to run a Python script

Wed Aug 26, 2020 6:36 pm

Zelatrix wrote:
Wed Aug 26, 2020 2:33 pm
then gives up, throwing an error telling me that the name couldn't be resolved.
Can you indicate where in the code that error appears?
Pi4 8GB running PIOS64 Lite

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Wed Aug 26, 2020 7:08 pm

I would, but it's somewhat difficult to make the error happen, since it isn't (AFAIK) triggered by a specific event. At least, not one that I know how to trigger manually.

hippy
Posts: 8522
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Unable to run a Python script

Thu Aug 27, 2020 12:10 am

Zelatrix wrote:
Wed Aug 26, 2020 7:08 pm
I would, but it's somewhat difficult to make the error happen, since it isn't (AFAIK) triggered by a specific event. At least, not one that I know how to trigger manually.
Wouldn't just pulling the ethernet cable to the PC do it ?

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Thu Aug 27, 2020 9:18 am

But then I would think it would be the same error with a different cause.

pcmanbob
Posts: 10117
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Unable to run a Python script

Thu Aug 27, 2020 10:38 am

The only way you are going to solve this is to have a screen and keyboard connected to your pi , then next time the program crashes run these commands from the command line and post the results.

Code: Select all


ifconfig

ip addr show

ip route

ip -4 route | awk '/default/ {print $3}'

ping -c3 $(ip route | awk '/default/ {print $3}')

ping -c3 8.8.8.8

ping -c3 google.com

cat /etc/resolv.conf
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Thu Aug 27, 2020 10:50 am

Can I just SSH into my Pi?

pcmanbob
Posts: 10117
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Unable to run a Python script

Thu Aug 27, 2020 10:54 am

Zelatrix wrote:
Thu Aug 27, 2020 10:50 am
Can I just SSH into my Pi?
Not if the network connection has failed, it depends on how you are connecting the pi and the PC and how each is connected to the network,
and which part of the network has failed.

and the answer to this question I was looking for was home, work , school, university etc...
What type of network is it connected to
It is connected to Ethernet
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Thu Aug 27, 2020 11:09 am

The network connection doesn't appear to have failed completely because I can still ping successfully, and the type of network I'm connected to is my home network.

pcmanbob
Posts: 10117
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Unable to run a Python script

Thu Aug 27, 2020 11:15 am

Zelatrix wrote:
Thu Aug 27, 2020 11:09 am
The network connection doesn't appear to have failed completely because I can still ping successfully, and the type of network I'm connected to is my home network.
Then if you run the commands I suggested it will help us figure out which part of your network has failed, but you need to wait for the program to fail so your pi is in the failed state

I suspect it will be DNS related because of the error message you get.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Thu Aug 27, 2020 1:44 pm

Code: Select all

pi@raspberrypi:/media/pi/SCRIPTS $ ifconfig
br-45931663853a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        inet6 fe80::42:8dff:fe3d:2680  prefixlen 64  scopeid 0x20<link>
        ether 02:42:8d:3d:26:80  txqueuelen 0  (Ethernet)
        RX packets 890919  bytes 142725012 (136.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1220339  bytes 1206296131 (1.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:ceff:fe98:3f9f  prefixlen 64  scopeid 0x20<link>
        ether 02:42:ce:98:3f:9f  txqueuelen 0  (Ethernet)
        RX packets 1898204  bytes 197099857 (187.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1383873  bytes 539170850 (514.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.63  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::b98a:de43:5df0:4a4f  prefixlen 64  scopeid 0x20<link>
        ether dc:a6:32:76:8e:e5  txqueuelen 1000  (Ethernet)
        RX packets 5044235  bytes 2499650158 (2.3 GiB)
        RX errors 0  dropped 177422  overruns 0  frame 0
        TX packets 2595934  bytes 335685687 (320.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1250  bytes 118672 (115.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1250  bytes 118672 (115.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth12c651e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fcc2:54ff:fe1a:bd47  prefixlen 64  scopeid 0x20<link>
        ether fe:c2:54:1a:bd:47  txqueuelen 0  (Ethernet)
        RX packets 216712  bytes 36970876 (35.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 214889  bytes 70338192 (67.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth21cf26f: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::8429:12ff:fe55:ccbe  prefixlen 64  scopeid 0x20<link>
        ether 86:29:12:55:cc:be  txqueuelen 0  (Ethernet)
        RX packets 99019  bytes 17304776 (16.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 119764  bytes 76128539 (72.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth53c9aa9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.16.81  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::2c0b:b5ff:fec0:4053  prefixlen 64  scopeid 0x20<link>
        ether 2e:0b:b5:c0:40:53  txqueuelen 0  (Ethernet)
        RX packets 6381  bytes 1491337 (1.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17805  bytes 13047004 (12.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth7d17f0b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.239.26  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::b657:5162:60bf:604d  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::88df:a0ff:fe0a:53aa  prefixlen 64  scopeid 0x20<link>
        ether 8a:df:a0:0a:53:aa  txqueuelen 0  (Ethernet)
        RX packets 1893115  bytes 223329164 (212.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1384161  bytes 529389936 (504.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethaa54308: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.232.45  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::3c99:6d2f:a37b:ef06  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::6803:53ff:fe93:385f  prefixlen 64  scopeid 0x20<link>
        ether 6a:03:53:93:38:5f  txqueuelen 0  (Ethernet)
        RX packets 195631  bytes 24700133 (23.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 516438  bytes 815537040 (777.7 MiB)
        TX errors 0  dropped 1 overruns 0  carrier 0  collisions 0

pi@raspberrypi:/media/pi/SCRIPTS $ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:76:8e:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.63/24 brd 192.168.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::b98a:de43:5df0:4a4f/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether dc:a6:32:76:8e:e7 brd ff:ff:ff:ff:ff:ff
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ce:98:3f:9f brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:ceff:fe98:3f9f/64 scope link
       valid_lft forever preferred_lft forever
8: br-45931663853a: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:8d:3d:26:80 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-45931663853a
       valid_lft forever preferred_lft forever
    inet6 fe80::42:8dff:fe3d:2680/64 scope link
       valid_lft forever preferred_lft forever
10: vethaa54308@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-45931663853a state UP group default
    link/ether 6a:03:53:93:38:5f brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 169.254.232.45/16 brd 169.254.255.255 scope global noprefixroute vethaa54308
       valid_lft forever preferred_lft forever
    inet6 fe80::3c99:6d2f:a37b:ef06/64 scope link
       valid_lft forever preferred_lft forever
    inet6 fe80::6803:53ff:fe93:385f/64 scope link
       valid_lft forever preferred_lft forever
16: veth53c9aa9@if15: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-45931663853a state UP group default
    link/ether 2e:0b:b5:c0:40:53 brd ff:ff:ff:ff:ff:ff link-netnsid 2
    inet 169.254.16.81/16 brd 169.254.255.255 scope global noprefixroute veth53c9aa9
       valid_lft forever preferred_lft forever
    inet6 fe80::2c0b:b5ff:fec0:4053/64 scope link
       valid_lft forever preferred_lft forever
18: veth7d17f0b@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether 8a:df:a0:0a:53:aa brd ff:ff:ff:ff:ff:ff link-netnsid 4
    inet 169.254.239.26/16 brd 169.254.255.255 scope global noprefixroute veth7d17f0b
       valid_lft forever preferred_lft forever
    inet6 fe80::b657:5162:60bf:604d/64 scope link
       valid_lft forever preferred_lft forever
    inet6 fe80::88df:a0ff:fe0a:53aa/64 scope link
       valid_lft forever preferred_lft forever
22: veth12c651e@if21: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-45931663853a state UP group default
    link/ether fe:c2:54:1a:bd:47 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::fcc2:54ff:fe1a:bd47/64 scope link
       valid_lft forever preferred_lft forever
28: veth21cf26f@if27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-45931663853a state UP group default
    link/ether 86:29:12:55:cc:be brd ff:ff:ff:ff:ff:ff link-netnsid 3
    inet6 fe80::8429:12ff:fe55:ccbe/64 scope link
       valid_lft forever preferred_lft forever
pi@raspberrypi:/media/pi/SCRIPTS $ ip route
default via 192.168.0.1 dev eth0 src 192.168.0.63 metric 202
169.254.0.0/16 dev vethaa54308 scope link src 169.254.232.45 metric 210
169.254.0.0/16 dev veth53c9aa9 scope link src 169.254.16.81 metric 216
169.254.0.0/16 dev veth7d17f0b scope link src 169.254.239.26 metric 218
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
172.18.0.0/16 dev br-45931663853a proto kernel scope link src 172.18.0.1
192.168.0.0/24 dev eth0 proto dhcp scope link src 192.168.0.63 metric 202
pi@raspberrypi:/media/pi/SCRIPTS $ ip -4 route | awk '/default/ {print $3}'
192.168.0.1
pi@raspberrypi:/media/pi/SCRIPTS $ ping -c3 $(ip route | awk '/default/ {print $3}')
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.

--- 192.168.0.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 65ms
Weirdly though, this is the second time I've run this (the formatting messed up the first time) and the first time it has 0% packet loss on the last command.

pcmanbob
Posts: 10117
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Unable to run a Python script

Thu Aug 27, 2020 1:57 pm

There were 8 commands to run , you have missed the last 3

Code: Select all

ping -c3 8.8.8.8

ping -c3 google.com

cat /etc/resolv.conf
The last command you ran were you got 100% packet loss indicates you don't have a connection to your router !

So it would be helpful to know how you have the pi connected to the router and your PC connected to the pi.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Zelatrix
Posts: 16
Joined: Sun Jul 12, 2020 4:06 pm

Re: Unable to run a Python script

Thu Aug 27, 2020 3:49 pm

Sorry, I didn't see those last 3. Here's the results:

Code: Select all

pi@raspberrypi:/media/pi/SCRIPTS $ ping -c 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=327 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=115 time=104 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=115 time=93.10 ms

--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 93.993/175.024/327.356/107.788 ms
pi@raspberrypi:/media/pi/SCRIPTS $ ping -c 3 google.com
PING google.com (216.58.207.78) 56(84) bytes of data.
64 bytes from fra16s25-in-f14.1e100.net (216.58.207.78): icmp_seq=1 ttl=113 time=132 ms
64 bytes from fra16s25-in-f14.1e100.net (216.58.207.78): icmp_seq=2 ttl=113 time=103 ms
64 bytes from fra16s25-in-f14.1e100.net (216.58.207.78): icmp_seq=3 ttl=113 time=98.7 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 4ms
rtt min/avg/max/mdev = 98.668/111.247/132.167/14.895 ms
pi@raspberrypi:/media/pi/SCRIPTS $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 192.168.0.1
nameserver 103.86.96.100
nameserver 103.86.99.100
nameserver 8.8.8.8
nameserver 8.8.4.4
And I'm connected to my Pi by an Ethernet cable which goes from the Pi into a WiFi extender which is plugged into a power strip, which is plugged into my wall.

scotty101
Posts: 4099
Joined: Fri Jun 08, 2012 6:03 pm

Re: Unable to run a Python script

Fri Aug 28, 2020 8:08 am

Have you tried adding a try-except to your code to handle that exception gracefully rather than exiting?

Code: Select all

try:
    someFunctionToGetStuffFromInternet()
except ConnectionError:
    print("An error occurred but I'm ignoring it this time")
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

pcmanbob
Posts: 10117
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Unable to run a Python script

Fri Aug 28, 2020 9:07 am

Well you obviously have a connection problem as you seem to have a connection to the internet now and when you first started running the tests

but at one point your ping failed and at that point you had not connection to the internet.

May be what you need to do is set up a simple ping test that runs every 120 seconds to see if you network drops out and if it does when and how often.

like this for example

Code: Select all

#!/bin/bash

# Test for connection
echo "................................................"
date "+%Y.%m.%d %H:%M:%S"
echo " "
ping -q -c2 google.com > /dev/null 

 
if [ $? != 0 ] 
then 
  echo " "
  echo "No network connection"
  
else
  echo " "
  echo "network connection OK"
     
fi
echo "................................................"
echo " "
you would then call this using cron assuming the file name is testlan.sh and you have made it executable.

Code: Select all

*/2 * * * * /home/pi/testlan.sh >> /home/pi/test.txt 2>&1
running this on my pi4 produced these results , the no connection was simply me pulling the LAN cable out to test it.

Code: Select all

 
................................................
2020.08.28 09:56:01
 
 
network connection OK
................................................
 
................................................
2020.08.28 09:58:01
 
ping: google.com: Temporary failure in name resolution
 
No network connection
................................................
 
................................................
2020.08.28 10:00:01
 
ping: google.com: Temporary failure in name resolution
 
No network connection
................................................
 
................................................
2020.08.28 10:02:01
 
 
network connection OK
................................................
 
................................................
2020.08.28 10:04:01
 
 
network connection OK
................................................
 
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pfletch101
Posts: 630
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: Unable to run a Python script

Sat Aug 29, 2020 11:09 pm

Zelatrix wrote:
Thu Aug 27, 2020 3:49 pm

And I'm connected to my Pi by an Ethernet cable which goes from the Pi into a WiFi extender which is plugged into a power strip, which is plugged into my wall.
Unfortunately, my experience is that WiFi extenders (I assume that you are actually using an Access Point as a WiFi bridge) are given to intermittent dropouts in anything other than very good locations. If the extender has a web page that displays connection information (many, if not most, of them do) I would look at it and check that it shows what the extender's documentation suggests is comfortably adequate WiFi signal strength. I have a whole-house power monitoring system whose gateway has to be near the breaker box where its sensors are installed. My main WiFi Access Point is at the other end of the main floor of my house. It turned out that I had to move my 'extender' to the other end of my basement (nearer the AP) and run ethernet cable back to the gateway to get reliable transmission, even though, to simple testing, it seemed to be OK when located by the gateway..

Return to “Troubleshooting”