Python Forum

Full Version: Fatal error?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!
So i have been working with python on Ubuntu which i boot from a pendrive on a computer whose hard disk is corrupted. I had taken the pen-drive off the computer while it was in sleep mode, used the pendrive on another computer and then plugged it back in to the sleeping computer. Just for fun, i thought i'll run it like that. BIG MISTAKE!
Now, even writing
import requests
gives me an error like this:
Error:
>>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/bunni/.local/lib/python3.6/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/home/bunni/.local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module> from .connectionpool import ( File "/home/bunni/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 36, in <module> from .response import HTTPResponse ValueError: source code string cannot contain null bytes
I tried uninstalling and reinstalling it using pip3, but it wont work either, and shows a similar error. This is not just with requests. even selenium doesnt work now.

All my files are preserved. No problems there, but no code is running.

Please advise what i can do to fix this problem

This is extremely weird.
import selenium
itself doesnt return any error, but
from selenium import webdriver
returns the following error:
Error:
from selenium import webdriver Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/__init__.py", line 18, in <module> from .firefox.webdriver import WebDriver as Firefox # noqa File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 29, in <module> from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 27, in <module> from .remote_connection import RemoteConnection File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 24, in <module> import urllib3 File "/home/bunni/.local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module> from .connectionpool import ( File "/home/bunni/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 36, in <module> from .response import HTTPResponse ValueError: source code string cannot contain null bytes >>> import pprint >>> import selenium >>> from selenium import webdriver Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/__init__.py", line 18, in <module> from .firefox.webdriver import WebDriver as Firefox # noqa File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 29, in <module> from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 27, in <module> from .remote_connection import RemoteConnection File "/home/bunni/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 24, in <module> import urllib3 File "/home/bunni/.local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module> from .connectionpool import ( File "/home/bunni/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 36, in <module> from .response import HTTPResponse ValueError: source code string cannot contain null bytes
It looks like only one file is not working properly...Any inputs on how to locate and fix it?

EDIT:
I'm able to import os, time, shutil, pprint, bs4, openpyxl normally.

Okay, so i followed the path in the traceback and found the corrupted file. Then replaced it with the file with the same name on GitHub. Now its working :)
Update:
The response file is fine now, but the socks file in contribs is showing the same error, and it is not resolving on doing what i did to correct the response file.
This is the error i get:
Error:
Traceback (most recent call last): File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored __import__(vendored_name, globals(), locals(), level=0) ModuleNotFoundError: No module named 'pip._vendor.cachecontrol' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/bin/pip3", line 9, in <module> from pip import main File "/usr/lib/python3/dist-packages/pip/__init__.py", line 22, in <module> from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 64, in <module> vendored("cachecontrol") File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored __import__(modulename, globals(), locals(), level=0) File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/__init__.py", line 9, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/wrapper.py", line 1, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 4, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/__init__.py", line 100, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/api.py", line 13, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/sessions.py", line 28, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/adapters.py", line 41, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 656, in _load_unlocked File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible File "/usr/share/python-wheels/urllib3-1.22-py2.py3-none-any.whl/urllib3/contrib/socks.py", line 27, in <module> ValueError: source code string cannot contain null bytes
Any help will be greatly appreciated!

okay, deleting the entire urllib3 folder from the path and reinstalling it worked for me.