AttributeError: module 'memcache' has no attribute 'Client' - python

Recently I implemented lock.py in my python project for locking threads, using memcached. However I encoutered an error which I have trouble solving. It says that memcache does not containt attribute Client. I am not using Client directly, I believe it's just being called inside the imported modules. I have installed both dogpile.cache==1.1.5 and python-memcached==1.59 using pip. Could someone please help me?
Here is the full error message:
Exception in thread Thread-1 (mock_process_repo):
Traceback (most recent call last):
File "/usr/lib64/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/home/jdonic/code/prograde/prograde/lock.py", line 164, in mock_process_repo
with RepoSyncLock("repository-name"):
File "/home/jdonic/code/prograde/prograde/lock.py", line 122, in __enter__
while not lock_cache_region.backend.client.add(
File "/home/jdonic/.local/lib/python3.10/site-packages/dogpile/cache/backends/memcached.py", line 181, in client
return self._clients.memcached
File "/home/jdonic/.local/lib/python3.10/site-packages/dogpile/util/langhelpers.py", line 78, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/home/jdonic/.local/lib/python3.10/site-packages/dogpile/cache/backends/memcached.py", line 169, in _clients
return ClientPool()
File "/home/jdonic/.local/lib/python3.10/site-packages/dogpile/cache/backends/memcached.py", line 167, in __init__
self.memcached = backend._create_client()
File "/home/jdonic/.local/lib/python3.10/site-packages/dogpile/cache/backends/memcached.py", line 313, in _create_client
return memcache.Client(self.url)
AttributeError: module 'memcache' has no attribute 'Client'

Related

Why is the pyspider module failing with"'collections' has no attribute 'MutableMapping'"?

After Pycharm installs pyspider,enter "pyspider all" on command,and an error is reported. C:
C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspider\libs\utils.py:196: FutureWarning: timeout is not supported on your platform.
warnings.warn("timeout is not supported on your platform.", FutureWarning)
[I 220529 09:16:16 result_worker:49] result_worker starting...
Exception in thread Thread-4 (invoke):
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspider\run.py", line 236, in fetcher
Fetcher = load_cls(None, None, fetcher_cls)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspider\run.py", line 48, in load_cls
return utils.load_object(value)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspider\libs\utils.py", line 369, in load_object
module = __import__(module_name, globals(), locals(), [object_name])
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspider\fetcher\__init__.py", line 1, in <module>
from .tornado_fetcher import Fetcher
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pyspider\fetcher\tornado_fetcher.py", line 21, in <module>
import tornado.httputil
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\tornado\httputil.py", line 106, in <module>
class HTTPHeaders(collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
How to solve this situation?

Python socket.io client fails on event with dictionary and list message

I have python-socketio==4.3.1 installed, and I can connect to the socket.io server correctly.
Whenever I receive a message though, I get an exception. The data I would get would be a list on the connect event, and a dictionary on message events.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 581, in _handle_eio_message
self._handle_event(pkt.namespace, pkt.id, pkt.data)
File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 470, in _handle_event
r = self._trigger_event(data[0], namespace, *data[1:])
File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 514, in _trigger_event
if namespace in self.handlers and event in self.handlers[namespace]:
TypeError: unhashable type: 'list'
Exception in thread Thread-6:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 581, in _handle_eio_message
self._handle_event(pkt.namespace, pkt.id, pkt.data)
File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 470, in _handle_event
r = self._trigger_event(data[0], namespace, *data[1:])
File "/usr/local/lib/python3.7/site-packages/socketio/client.py", line 514, in _trigger_event
if namespace in self.handlers and event in self.handlers[namespace]:
TypeError: unhashable type: 'dict'
I am able to log the messages correctly with a node client. Any ideas?
Code is just this right now:
import socketio
io = socketio.Client()
#io.event
def connect():
print('connected')
#io.event
def message(data):
print(data)
url = '...'
io.connect(url)
Turns out the error was in the server implementation.

AttributeError: module 'builtins' has no attribute 'interpreter'

It is a basic question, I guess.
I can run my program in Pycharm 2018.1 Python 3.6.5. But when I run in debug mode and open python console, I get this error message when I try to key in any python command.
I am using virtualenv and added interpreter in project setting.
I wonder what's wrong with my configuration
below is stacktrace
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevconsole.py", line 362, in get_interpreter
interpreterInterface = getattr(__builtin__, 'interpreter')
AttributeError: module 'builtins' has no attribute 'interpreter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1443, in do_it
result = pydevconsole.console_exec(self.thread_id, self.frame_id, self.expression, dbg)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevconsole.py", line 467, in console_exec
need_more = exec_code(CodeFragment(expression), updated_globals, frame.f_locals, dbg)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevconsole.py", line 383, in exec_code
interpreterInterface = get_interpreter()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevconsole.py", line 364, in get_interpreter
interpreterInterface = InterpreterInterface(None, None, threading.currentThread())
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_ipython_console.py", line 24, in __init__
self.interpreter = get_pydev_frontend(host, client_port)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 461, in get_pydev_frontend
_PyDevFrontEndContainer._instance = _PyDevFrontEnd()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 310, in __init__
self.ipython = PyDevTerminalInteractiveShell.instance()
File "/Users/hobart/envs/pys/lib/python3.6/site-packages/traitlets/config/configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "/Users/hobart/envs/pys/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 430, in __init__
super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
File "/Users/hobart/envs/pys/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 516, in __init__
self.init_completer()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 234, in init_completer
self.Completer = self._new_completer_500()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 196, in _new_completer_500
parent=self
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 87, in __init__
self.matchers.remove(self.python_matches)
ValueError: list.remove(x): x not in list
This was fixed few days after your question: https://youtrack.jetbrains.com/issue/PY-29313
You should update your PyCharm to 2018.1.1 or higher.
I had exactly the same problem after trying to install some packages into the virtual environment. For me it was solved by recreating the environment.

ev3 closes connection when I attempt to connect through rpyc in python

I installed ev3dev on my ev3 brick so I could create programs on it with python. I am trying to use the "rpyc" library for python which can be found here. However, when I try to run this basic script which is given as an example on the link above:
import rpyc
conn = rpyc.classic.connect('192.168.137.3') # host name or IP address of the EV3
ev3 = conn.modules['ev3dev.ev3'] # import ev3dev.ev3 remotely
m = ev3.LargeMotor('outA')
m.run_timed(time_sp=1000, speed_sp=600)
I get multiple errors thrown at me through the terminal followed by the connection closing. I have followed all the instructions on the page and I also started the server script on the ev3 brick beforehand. When I run the above program the errors from python are displayed:
Traceback (most recent call last):
File "C:/Python27/cooode/moottertest.py", line 2, in <module>
conn = rpyc.classic.connect('192.168.137.3') # host name or IP address of the EV3
File "C:\Python27\lib\site-packages\rpyc\utils\classic.py", line 65, in connect
return factory.connect(host, port, SlaveService, ipv6 = ipv6)
File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 90, in connect
return connect_stream(s, service, config)
File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 51, in connect_stream
return connect_channel(Channel(stream), service = service, config = config)
File "C:\Python27\lib\site-packages\rpyc\utils\factory.py", line 40, in connect_channel
return Connection(service, channel, config = config)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 147, in __init__
self._init_service()
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 150, in _init_service
self._local_root.on_connect()
File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 145, in on_connect
self._conn.builtin = self._conn.modules.__builtin__
File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 114, in __getattr__
return self[name]
File "C:\Python27\lib\site-packages\rpyc\core\service.py", line 111, in __getitem__
self.__cache[name] = self.__getmodule(name)
File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 196, in __call__
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "C:\Python27\lib\site-packages\rpyc\core\netref.py", line 71, in syncreq
return conn.sync_request(handler, oid, *args)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 435, in sync_request
self.serve(0.1)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 383, in serve
data = self._recv(timeout, wait_for_lock = True)
File "C:\Python27\lib\site-packages\rpyc\core\protocol.py", line 341, in _recv
data = self._channel.recv()
File "C:\Python27\lib\site-packages\rpyc\core\channel.py", line 50, in recv
header = self.stream.read(self.FRAME_HEADER.size)
File "C:\Python27\lib\site-packages\rpyc\core\stream.py", line 190, in read
raise EOFError("connection closed by peer")
EOFError: connection closed by peer
>>>
Then on my SSH session, here are the errors that are displayed:
robot#ev3dev:~$ ./rpyc_server.sh
INFO:SLAVE/18812:server started on [0.0.0.0]:18812
INFO:SLAVE/18812:accepted 192.168.137.1:5725
INFO:SLAVE/18812:welcome [192.168.137.1]:5725
INFO:SLAVE/18812:goodbye [192.168.137.1]:5725
ERROR:SLAVE/18812:client connection terminated abruptly
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
self._serve_client(sock2, credentials)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
conn._init_service()
File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
self._local_root.on_connect()
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
self._conn.builtin = self._conn.modules.builtins
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
return self[name]
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 172, in _authenticate_and_serve_client
self._serve_client(sock2, credentials)
File "/usr/lib/python3/dist-packages/rpyc/utils/server.py", line 197, in _serve_client
conn._init_service()
File "/usr/lib/python3/dist-packages/rpyc/core/protocol.py", line 154, in _init_service
self._local_root.on_connect()
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 150, in on_connect
self._conn.builtin = self._conn.modules.builtins
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 121, in __getattr__
return self[name]
File "/usr/lib/python3/dist-packages/rpyc/core/service.py", line 118, in __getitem__
self.__cache[name] = self.__getmodule(name)
TypeError: 'b'instancemethod'' object is not callable
What is going wrong here in these errors?
Are you connecting python2 and python3? ev3dev uses python2.
Use pyenv to install python3 and use it so that your python version of PC and ev3 are the same.
https://gist.github.com/jaydenkieran/75b2bbc32b5b70c4fdfb161ecdb6daa2
You might need to run this command first to install through curl:
sudo apt-get install curl

Django testrunner not working properly

the following code:
class CreateSurveyFromCsvTextTests(TestCase):
def test_parses_survey_passed_in_as_csv_and_returns_xml_representation(self):
self.assertTrue(True)
throws the following error:
ERROR: test_parses_survey_passed_in_as_csv_and_returns_xml_representation (dkobo.formbuilder.tests.CreateSurveyFromCsvTextTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/test/testcases.py", line 178, in __call__
self._pre_setup()
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/test/testcases.py", line 749, in _pre_setup
self._fixture_setup()
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/test/testcases.py", line 861, in _fixture_setup
if not connections_support_transactions():
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/test/testcases.py", line 848, in connections_support_transactions
for conn in connections.all())
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/test/testcases.py", line 848, in <genexpr>
for conn in connections.all())
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 664, in supports_transactions
self.connection.leave_transaction_management()
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 317, in leave_transaction_management
if managed == self.get_autocommit():
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
self.ensure_connection()
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/home/nico/.virtualenvs/kf/local/lib/python2.7/site-packages/django/db/utils.py", line 86, in __exit__
db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
----------------------------------------------------------------------
I know this doesn't tell you much about the problem, and it's probably an environment problem, but I'm new to Linux/Python (switched from Windows/.Net 7 days ago) and wouldn't really know where to start gathering information, let alone diagnosing the error.
The problem was that the database was not configured. Adding the default entry for DATABASE in settings.py and the running python manage.py syncdb fixed it.

Categories

Resources