Detect if the internet connection is offline?

Almost all major browsers now support the window.navigator.onLine property, and the corresponding online and offline window events. Run the following code snippet to test it: console.log(‘Initially ‘ + (window.navigator.onLine ? ‘on’ : ‘off’) + ‘line’); window.addEventListener(‘online’, () => console.log(‘Became online’)); window.addEventListener(‘offline’, () => console.log(‘Became offline’)); document.getElementById(‘statusCheck’).addEventListener(‘click’, () => console.log(‘window.navigator.onLine is ‘ + window.navigator.onLine)); <button id=”statusCheck”>Click … Read more

Pass a PHP variable to a JavaScript variable

Expanding on someone else’s answer: <script> var myvar = <?= json_encode($myVarValue, JSON_UNESCAPED_UNICODE); ?>; </script> Using json_encode() requires: PHP 5.2.0 or greater $myVarValue encoded as UTF-8 (or US-ASCII, of course) Since UTF-8 supports full Unicode, it should be safe to convert on the fly. Please note that if you use this in html attributes like onclick, … Read more

Why do I get “AttributeError: NoneType object has no attribute” using Tkinter? Where did the None value come from?

The grid, pack and place functions of the Entry object and of all other widgets returns None. In python when you do a().b(), the result of the expression is whatever b() returns, therefore Entry(…).grid(…) will return None. You should split that on to two lines like this: entryBox = Entry(root, width=60) entryBox.grid(row=2, column=1, sticky=W) That … Read more

One try block with multiple excepts

Yes, it is possible. try: … except FirstException: handle_first_one() except SecondException: handle_second_one() except (ThirdException, FourthException, FifthException) as e: handle_either_of_3rd_4th_or_5th() except Exception: handle_all_other_exceptions() See: The “as” keyword is used to assign the error to a variable so that the error can be investigated more thoroughly later on in the code. Also note that the parentheses … Read more

org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection Selenium ChromeDriver and Chrome v111

Using google-chrome v111.0 this error message… org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:49877/devtools/browser/3a3af47d-732a-4337-a91c-18c8ced545cd and this error message… 2023-03-08T21:06:50.3319163Z WARNING: Invalid Status code=403 text=Forbidden 2023-03-08T21:06:50.3320374Z Invalid Status code=403 text=Forbidden and even this error message… java.lang.NullPointerException: Cannot invoke “, String)” because “this.socket” is null …is the result of devtools_http_handler rejecting an incoming WebSocket connection from … Read more

Error “The authenticity of host ‘’ can’t be established. RSA key fingerprint “

You should simply be able to answer ‘yes‘, which will update your ~/.ssh/known_hosts file. A better approach, to avoid any MITM (Man-In-The-Middle) attack, would be (as commented below by Mamsds) to verify GitHub’s public key first (see “GitHub’s SSH key fingerprints“) and, if you find a match, then you can answer ‘yes’. Example: ssh-keyscan -t … Read more

How do I check if a directory exists in Python?

Use os.path.isdir for directories only: >>> import os >>> os.path.isdir(‘new_folder’) True Use os.path.exists for both files and directories: >>> import os >>> os.path.exists(os.path.join(os.getcwd(), ‘new_folder’, ‘file.txt’)) False Alternatively, you can use pathlib: >>> from pathlib import Path >>> Path(‘new_folder’).is_dir() True >>> (Path.cwd() / ‘new_folder””file.txt’).exists() False