Heads up, this will be long. My python is really broken, and i dont know how to fix it. It all started after my VSCODE pylance stopped working. I, for some reason, tried uninstalling my python, and here i am. So basically, I have a script that uses the discord-webhook library to send stuff to my Discord. I dont know what i did but now when i run the script, everything works, all functions and code works, until i get to webhook.execute(). I get this error(btw i was running this on 3.9.12 but have now switched to 3.10.0 and it is still broken):
Traceback (most recent call last):
File "e:PythonProjectsProjectsDiscordWebhook.py", line 828, in <module>
webhook.execute()
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesdiscord_webhookwebhook.py", line 444, in execute
response = self.api_post_request()
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesdiscord_webhookwebhook.py", line 397, in api_post_request
return requests.post(
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesrequestsapi.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
return session.request(method=method, url=url, **kwargs)
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesrequestssessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesrequestssessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesrequestsadapters.py", line 458, in send
self.cert_verify(conn, request.url, verify, cert)
File "C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagesrequestsadapters.py", line 261, in cert_verify
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: C:UsersAdminAppDataLocalProgramsPythonPython310libsite-packagescertificacert.pem
And then some of my libraries uninstall or aren’t recognised,and python is removed from PATH, and then I try running pip to reinstall and i get this error:
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'C:UsersAdminAppDataLocalProgramsPythonPython310python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\Users\Admin\AppData\Local\Programs\Python\Python310\python.exe'
sys.base_prefix = ''
sys.base_exec_prefix = ''
sys.platlibdir = 'lib'
sys.executable = 'C:\Users\Admin\AppData\Local\Programs\Python\Python310\python.exe'
sys.prefix = ''
sys.exec_prefix = ''
sys.path = [
'C:\Users\Admin\AppData\Local\Programs\Python\Python310\python310.zip',
'C:\Users\Admin\AppData\Local\Programs\Python\Python310\Lib\',
'C:\Users\Admin\AppData\Local\Programs\Python\Python310\DLLs\',
'C:\Users\Admin\AppData\Local\Programs\Python\Python310',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00002fe8 (most recent call first):
<no Python frame>
And now i cant run and script, run any python related command(pip, python) and if i reinstall python, same errors, install a new version, same errors.
Here are some big fixes and things i have tried:
Removed PYTHONHOME and PYTHONPATH system variables
Removed Python environment variable from my windows user profile
Uninstalled python 3.9.12 from my pc using Microsoft_Program_uninstall_reinstall_debugger.exe
Uninstalled all python versions from my pc using control panel and their files
sfc /scannow
After i get first error, i tried running python -m pip uninstall certifi
reinstalled VSCODE because i thought that was the problem
Can someone please help. Because i now cannot code.
2
Answers
Turns out i forgot to remove a line of code, shown here:
remove_all_zip_files(os.path.dirname(sys.executable))
which would remove all folders and files from the specified path, however, it would remove all folders and files from my python installation. which is why no certificate or module named encodings was found. Sorry for any hassle!system and then reinstalling it from the official Python website.