ImportError: cannot import name 'SimpleCookie' error - python

I tried to runserver with the manage.py but I get this error.
I am a newbie in django framework. I am following tutsplus tutorial for news aggregator.
bash -cl "/Users/Spandan/PycharmProjects/newsproject/venv/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/django_manage.py runserver /usr/local/lib/python3.6/site-packages/django"
Traceback (most recent call last):
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/__init__.py", line 16, in setup
from django.urls import set_script_prefix
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/urls/base.py", line 8, in <module>
from .exceptions import NoReverseMatch, Resolver404
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/urls/exceptions.py", line 1, in <module>
from django.http import Http404
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/http/__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
File "/Users/Spandan/PycharmProjects/newsproject/venv/lib/python3.6/site-packages/django/http/cookie.py", line 2, in <module>
from http import cookies
File "/usr/local/lib/python3.6/site-packages/django/http/__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
ImportError: cannot import name 'SimpleCookie'

Related

Python throwing error around API when using requests

I'm new to APIs and am following the exact instructions of every website explaining how one is supposed to get help of the APIs in Python using the requests module. However, no matter what API link I define (of course I went for many free API samples just to test if they work), I get this error: ImportError: cannot import name 'b64encode' from 'base64'
I have no idea what the problem is, or what I'm not getting right.
Here's my snippet, just as a sample:
import requests
words = 30
paragraphs = 1
formats = 'text'
response = requests.get(f"https://v2.jokeapi.dev/")
print(response.text)
The complete error I get is like so:
Traceback (most recent call last):
File "/home/liana/Desktop/testing.py", line 1, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/usr/lib/python3/dist-packages/urllib3/exceptions.py", line 3, in <module>
from six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/usr/lib/python3/dist-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python3/dist-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python3/dist-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/lib/python3.9/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.9/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.9/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.9/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/lib/python3.9/email/header.py", line 17, in <module>
import email.base64mime
File "/usr/lib/python3.9/email/base64mime.py", line 37, in <module>
from base64 import b64encode
ImportError: cannot import name 'b64encode' from 'base64' (/home/liana/Desktop/base64.py)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.9/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.9/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.9/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.9/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.9/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/lib/python3.9/email/header.py", line 17, in <module>
import email.base64mime
File "/usr/lib/python3.9/email/base64mime.py", line 37, in <module>
from base64 import b64encode
ImportError: cannot import name 'b64encode' from 'base64' (/home/liana/Desktop/base64.py)
Original exception was:
Traceback (most recent call last):
File "/home/liana/Desktop/testing.py", line 1, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 11, in <module>
from . import exceptions
File "/usr/lib/python3/dist-packages/urllib3/exceptions.py", line 3, in <module>
from six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "/usr/lib/python3/dist-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python3/dist-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python3/dist-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/lib/python3.9/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.9/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.9/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/lib/python3.9/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/lib/python3.9/email/header.py", line 17, in <module>
import email.base64mime
File "/usr/lib/python3.9/email/base64mime.py", line 37, in <module>
from base64 import b64encode
ImportError: cannot import name 'b64encode' from 'base64' (/home/liana/Desktop/base64.py)
Any help is appreciated.
If you look carefully at the traceback, you will see that it starts with your script, "/home/liana/Desktop/testing.py", goes through a chain of imports, and ends up crashing trying to import b64encode from base64.py.
The file /home/liana/Desktop/base64.py is something you either created or downloaded. Since it's in the current directory, it supersedes the real base64.py that "/usr/lib/python3.9/email/base64mime.py" is looking for. The file in your current directory clearly does not define the name b64encode, which is the immediate cause of the error.
To fix the problem, make sure the names of the files in your current directory don't conflict with the names of other top level modules. So either rename it delete /home/liana/Desktop/base64.py.

DLL failed importing SSL

I've got this lengthy error from SSL:
Traceback (most recent call last):
File "c:\Users\bala006\OneDrive - St John's Anglican College\Desktop\Personal\Pro Torch\Cats vs Dogs\osm.py", line 1, in <module>
from geopy.geocoders import Nominatim
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\geopy\__init__.py", line 12, in <module>
from geopy.geocoders import * # noqa
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\geopy\geocoders\__init__.py", line 221, in <module>
from geopy.geocoders.algolia import AlgoliaPlaces
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\geopy\geocoders\algolia.py", line 5, in <module>
from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\geopy\geocoders\base.py", line 7, in <module>
from geopy.adapters import (
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\geopy\adapters.py", line 22, in <module>
from ssl import SSLError
File "C:\Users\bala006\Miniconda3.8\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified module could not be found
Every single fix provided online is useless. I've successfully installed it using conda(I use miniconda) but when I try using pip I get this
Traceback (most recent call last):
File "C:\Users\bala006\Miniconda3.8\Scripts\pip-script.py", line 6, in <module>
from pip._internal.cli.main import main
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\cli\main.py", line 8, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\cli\autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\cli\main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 22, in <module>
from pip._internal.cli.progress_bars import BAR_TYPES
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\cli\progress_bars.py", line 9, in <module>
from pip._internal.utils.logging import get_indentation
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\utils\logging.py", line 14, in <module>
from pip._internal.utils.misc import ensure_dir
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\utils\misc.py", line 29, in <module>
from pip._internal.locations import get_major_minor_version, site_packages, user_site
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\locations\__init__.py", line 9, in <module>
from . import _distutils, _sysconfig
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\locations\_sysconfig.py", line 8, in <module>
from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
ImportError: cannot import name 'InvalidSchemeCombination' from 'pip._internal.exceptions' (C:\Users\bala006\Miniconda3.8\lib\site-packages\pip\_internal\exceptions.py)
What should I do?

Python import error even though relevant module is installed

I'm trying to run Python behave tests but get the following error:
[moadmin#modevvm12 e2e-tests]$ behave -i features/tests/connmgr_2_scan_management_container.feature
Exception ImportError: No module named request
Traceback (most recent call last):
File "/usr/bin/behave", line 11, in <module>
sys.exit(main())
File "/usr/lib/python2.7/site-packages/behave/__main__.py", line 183, in main
return run_behave(config)
File "/usr/lib/python2.7/site-packages/behave/__main__.py", line 127, in run_behave
failed = runner.run()
File "/usr/lib/python2.7/site-packages/behave/runner.py", line 804, in run
return self.run_with_paths()
File "/usr/lib/python2.7/site-packages/behave/runner.py", line 808, in run_with_paths
self.load_hooks()
File "/usr/lib/python2.7/site-packages/behave/runner.py", line 784, in load_hooks
exec_file(hooks_path, self.hooks)
File "/usr/lib/python2.7/site-packages/behave/runner_util.py", line 386, in exec_file
exec(code, globals_, locals_)
File "features/environment.py", line 20, in <module>
from framework.sd.api.auth_rbac import AuthRBAC
File "/tmp/e2e-tests/framework/sd/api/auth_rbac.py", line 10, in <module>
from framework.sd.api.sd_endpoint import SDEndpoint
File "/tmp/e2e-tests/framework/sd/api/sd_endpoint.py", line 12, in <module>
import urllib.request, urllib.parse, urllib.error
ImportError: No module named request
urllib is installed so I can't understand why I get this error.

cannot import name 'Type'

I would like to know what this error is about.
It pops up after I run a small script using this lib -->
from sklearn.feature_extraction.text import TfidfVectorizer
Traceback (most recent call last):
File "C:/Users/migue/PycharmProjects/research4me/tfidf.py", line 17, in <module>
getUniqueWords(text)
File "C:/Users/migue/PycharmProjects/research4me/tfidf.py", line 3, in getUniqueWords
from sklearn.feature_extraction.text import TfidfVectorizer
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\sklearn\__init__.py", line 82, in <module>
from .base import clone
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\sklearn\base.py", line 20, in <module>
from .utils import _IS_32BIT
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
from scipy.sparse import issparse
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\scipy\__init__.py", line 156, in <module>
from . import fft
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\scipy\fft\__init__.py", line 76, in <module>
from ._basic import (
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\scipy\fft\_basic.py", line 1, in <module>
from scipy._lib.uarray import generate_multimethod, Dispatchable
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\scipy\_lib\uarray.py", line 27, in <module>
from ._uarray import *
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\scipy\_lib\_uarray\__init__.py", line 114, in <module>
from ._backend import *
File "C:\Users\migue\PycharmProjects\research4me\venv\lib\site-packages\scipy\_lib\_uarray\_backend.py", line 1, in <module>
from typing import (
ImportError: cannot import name 'Type'

Django won't start with a wierd error "AttributeError: 'module' object has no attribute 'getargspec'"

I'm a bit inexperienced when it comes to Django's internals so I'm completely stuck now. It worked yesterday, and I can't remember I've changed anything significant.
When I turn DEBUG=True there is a stack trace on any module which happens to be first in the list
Traceback (most recent call last):
File "/home/yury/PycharmProjects/mezzamine/findmeals/mezzamine/manage.py", line 28, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/usr/local/lib/python3.4/dist-packages/django/utils/log.py", line 13, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/usr/local/lib/python3.4/dist-packages/django/http/__init__.py", line 4, in <module>
from django.http.response import (
File "/usr/local/lib/python3.4/dist-packages/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/base.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python3.4/dist-packages/django/db/__init__.py", line 98, in <module>
signals.request_started.connect(reset_queries)
File "/usr/local/lib/python3.4/dist-packages/django/dispatch/dispatcher.py", line 99, in connect
argspec = inspect.getargspec(receiver)
AttributeError: 'module' object has no attribute 'getargspec'
And when I turn DEBUG=False it complains about
Traceback (most recent call last):
File "/home/yury/PycharmProjects/mezzamine/findmeals/mezzamine/manage.py", line 28, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/usr/local/lib/python3.4/dist-packages/django/utils/log.py", line 13, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/usr/local/lib/python3.4/dist-packages/django/http/__init__.py", line 4, in <module>
from django.http.response import (
File "/usr/local/lib/python3.4/dist-packages/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/usr/local/lib/python3.4/dist-packages/django/core/serializers/base.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python3.4/dist-packages/django/db/models/__init__.py", line 8, in <module>
from django.db.models.manager import Manager # NOQA
File "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", line 63, in <module>
class BaseManager(six.with_metaclass(RenameManagerMethods)):
File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 778, in __new__
return meta(name, bases, d)
File "/usr/local/lib/python3.4/dist-packages/django/utils/deprecation.py", line 50, in __new__
for base in inspect.getmro(new_class):
AttributeError: 'module' object has no attribute 'getmro'
I use Django 1.7.8 and Mezzanine 3 and tried upgrading and reinstalling them with no luck. Could anyone give a hint on what's wrong?
You have a local file called "inspect.py" that is shadowing the stdlib module. Name your file something else.
django/utils/inspect.pyc is shadowing standard library inspect.py
django/utils/inspect.py was added in Django 1.9 and compiled binary file is left after you downgraded to 1.7.8

Categories

Resources