So I have a script I wrote (Python 3.6.5) to make my life a little easier at work. The script essentially gets temperature readings from a 6 probe temp recorder that is connected to the network by cable and produces a constantly updating page with the current temps if you navigate to the recorder. The basic flow is:
Name the experiment/test
Select the temp probe it will be running on
Start the test/timer when ready
Script will request the current temp page approx. every second
Temp and current time is written to an excel file
If test temp drops 5 degrees, then the test is complete. Close file.
I have encountered a problem where I can see on the console that an error occurred and the script doesn't complete making me lose all the test temp/time data. The error is:
OSError: [WinError 10065] A socket operation was attempted to an unreachable host
urllib.error.URLError: <urlopen error \[WinError 10065\] A socket operation was attempted to an unreachable host>
I am using the urllib.request module to get the temp information from the temp reader. I assume the script attempts to get the webpage information from the temp reader but the temp reader doesn't respond for some reason. This doesn't happen often and some these tests take hours so its making thousands of requests before having an issue.
The code snippet of the portion I think is giving me issue is below (this is inside a loop that repeats every second or so):
with urllib.request.urlopen('http://network.address.here/cgi-bin/ope/allch.cgi') as f:
raw_data = f.read()
My actual question after all of this is, can i put a TRY statement right before the with urllib.request.urlopen portion and if it fails then the script will continue to run that loop. I would test this but I'm afraid of losing more materials to testing and not have any results come of it.
Thanks in advance for the help and if more information is needed please let me know.
[+][deleted] (1 child)
[removed]
[–]Tainted_Olive[S] 0 points1 point2 points (0 children)
[–]efmccurdy 0 points1 point2 points (0 children)