Python 3.3: Catching HTTPError with Timer -


I'm trying to study Python and I want to try to capture a server time out (if my internet connection is interrupted or something else) and by adding a timer that will stop the process for x seconds (below) Code is 2 seconds) then try to continue the process though I believe my argument is correct (please correct me if I am wrong), I get an error Thread Thread-1: Traceback (most recent call final): "C: \ Python33 \ lib \ threading.py", in line 639, _bootstrap_inner .run () file "C: \ Python33 \ lib \ threading.py", line 825, run self.function (* auto.rgs, ** self.kwargs) TypeError: 'any type' object is not worth the corner

I do not understand why my timer triggers and error is my code:

  import urllib.request timer with import threading REQ = urllib.request.Request ('http: //www.nowebsitec Ontainsthisaddress.com ') def servertimeout (e): timer_rest = timer (2.0, print (' timeout error: ')) timer_st. Start () print (E.Reson) while timer_steas_live (): True while attempting: try: url = urllib.request.urlopen (req) brake except urlib.error.HTTP e: serverTimeOut (e) req = urllib Request.Request ('http://www.google.com') leaving urllib.error.URLError as e: servertimeout (e) req = urllib request. Request ('http://www.google.com')   

Using OS is Windows 7

Update: Hi guys, I have to tweaking my code on it I have tried and there is no error. I hope someone has raised me so why the error has occurred .. thanks ^^,

  import import urllib.request importing timer req Def print message ('http: /www.nowebsitecontenssthisaddress.com'): print ('timeout error:') def servertimeout (e): timer_st = timer (2.0, print message) timer_ Rest.start () print (E.Reson) while timer_st. Is_alive (): True while passing: Try: url = urllib.request.urlopen (req) urlib.error.HTTP except e-server: servertimeout (e) req = urllib.request.Request ('http: // Www.google .com ') as urlib.error.URLError as E: ServerTimeOut (e) req = urllib.request.Request (' http://www.google.com ')    

When you create a timer, you are calling a print function. The correct way to create your timer is by timer (2.0, print, 'time out error') .

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -