Test cases are failing using mongomock pymongo mongoengine - mongoengine

I am trying to run test cases with mongomock having pymongo version as 2.X and mongoengine 0.10.6
I have tried to change the version for pymongo to 2.9.5 from 2.6.3 and mongoengine from 0.10.6 to 0.17.0. I have tried with mongomock from 3.0.0 to 3.17.0
#classmethod
def setUpClass(cls):
super(MongoTestCase, cls).setUpClass()
cls.conn = mongoengine.connect(
settings.MONGODB_NAME,
host=settings.MONGODB_DATABASE_HOST,
alias="default",
is_mock=True
)
I expect the test case to pass with message currently I am getting
======================================================================
ERROR: test_ibest_matches (packages.tests.test_utils.test_ibest_matches.TestIBestMatches)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/www/packages/tests/test_utils/test_ibest_matches.py", line 56, in test_ibest_matches
**context))
File "/www/packages/utils.py", line 228, in ibest_matches
for vc in valid_contexts
File "/www/packages/managers/base_package_manager.py", line 111, in best_matches
for group, packages in groupby(pkgs, key=lambda k: k.group):
File "/usr/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 97, in _iter_results
self._populate_cache()
File "/usr/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 116, in _populate_cache
self._result_cache.append(self.next())
File "/usr/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 1407, in next
raw_doc = self._cursor.next()
File "/usr/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 1482, in _cursor
**self._cursor_args)
TypeError: find() got an unexpected keyword argument 'fields'
----------------------------------------------------------------------
Ran 44 tests in 3.273s
FAILED (errors=26)

Related

Raise error, v # invalid expression when trying to create azure nic interface via az cli

I am trying to create Network interface on Azure using AZ Cli command and it is showing following error.
Ansible modules for the same have some hard requirements of urllib3 and requests package hence trying to use Azure cli.
The stacktrace looks like its a module issue.
/root/bin/lib/python2.7/site-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a release (2.7.7+) that supports hmac.compare_digest as soon as possible.
utils.PersistentlyDeprecated2018,
The command failed with an unexpected error. Here is the traceback:
nothing to repeat
Traceback (most recent call last):
File "/root/bin/lib/python2.7/site-packages/knack/cli.py", line 206, in invoke
cmd_result = self.invocation.execute(args)
File "/root/bin/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 523, in execute
self.commands_loader.load_arguments(command)
File "/root/bin/lib/python2.7/site-packages/azure/cli/core/__init__.py", line 291, in load_arguments
self.command_table[command].load_arguments() # this loads the arguments via reflection
File "/root/bin/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 290, in load_arguments
super(AzCliCommand, self).load_arguments()
File "/root/bin/lib/python2.7/site-packages/knack/commands.py", line 97, in load_arguments
cmd_args = self.arguments_loader()
File "/root/bin/lib/python2.7/site-packages/azure/cli/core/__init__.py", line 488, in default_arguments_loader
op = handler or self.get_op_handler(operation, operation_group=kwargs.get('operation_group'))
File "/root/bin/lib/python2.7/site-packages/azure/cli/core/__init__.py", line 528, in get_op_handler
op = import_module(mod_to_import)
File "/opt/rh/python27/root/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/bin/lib/python2.7/site-packages/azure/cli/command_modules/network/custom.py", line 23, in <module>
from azure.cli.command_modules.network.zone_file.parse_zone_file import parse_zone_file
File "/root/bin/lib/python2.7/site-packages/azure/cli/command_modules/network/zone_file/__init__.py", line 28, in <module>
from azure.cli.command_modules.network.zone_file.parse_zone_file import parse_zone_file
File "/root/bin/lib/python2.7/site-packages/azure/cli/command_modules/network/zone_file/parse_zone_file.py", line 77, in <module>
_COMPILED_REGEX = {k: re.compile(v, re.IGNORECASE) for k, v in _REGEX.items()}
File "/root/bin/lib/python2.7/site-packages/azure/cli/command_modules/network/zone_file/parse_zone_file.py", line 77, in <dictcomp>
_COMPILED_REGEX = {k: re.compile(v, re.IGNORECASE) for k, v in _REGEX.items()}
File "/root/bin/lib64/python2.7/re.py", line 190, in compile
return _compile(pattern, flags)
File "/root/bin/lib64/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
error: nothing to repeat```
Following packages I am using for az cli :
azure-cli 2.0.71
azure-cli-command-modules-nspkg 2.0.3
azure-cli-core 2.0.35
azure-cli-nspkg 3.0.2
azure-cli-telemetry 1.0.3
It seems your python version need to be upgraded, could you please upgrade your python to 2.7.7

anaconda navigator will no longer start even through cmd, won't install or update or manage environments

I'm new to django and using the anaconda cloud environment. Its been working well for 3 months plus but as of 7-24-2018 it is just stop to launch the navigator or open through cmd. I can't manage environments or install packages. Using the anaconda prompt also gives me the same error upon launching. It started when I wanted to install django-Oscar, but not having its dependencies I was forced to install the packages manually which in turn needed cytoolz that needs Microsoft Visual C++ build tools which I got to install as well but the error persists. Please help me!
Copy/Paste of CMD Traceback:
C:\Users\kaukau\Desktop>conda --version conda 4.5.4
C:\Users\kaukau\Desktop>anaconda-navigator Traceback (most recent call
last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\qtpy__init__.py", line
169, in
from PySide import version as PYSIDE_VERSION # analysis:ignore ModuleNotFoundError: No module named 'PySide'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\Scripts\anaconda-navigator-script.py", line
6, in
from anaconda_navigator.app.main import main File "C:\Users\kaukau\Anaconda3\lib\site-packages\anaconda_navigator\app\main.py",
line 22, in
from anaconda_navigator.utils.conda import is_conda_available File
"C:\Users\kaukau\Anaconda3\lib\site-packages\anaconda_navigator\utils__init__.py",
line 15, in
from qtpy.QtGui import QIcon File "C:\Users\kaukau\Anaconda3\lib\site-packages\qtpy__init__.py", line
175, in
raise PythonQtError('No Qt bindings could be found') qtpy.PythonQtError: No Qt bindings could be found
C:\Users\kaukau\Desktop>conda install qt --force Traceback (most
recent call last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 42, in
from cytoolz.dicttoolz import merge File "C:\Users\kaukau\Anaconda3\lib\site-packages\cytoolz__init__.py",
line 1, in
from .itertoolz import * ModuleNotFoundError: No module named 'cytoolz.itertoolz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 819, in call
return func(*args, **kwargs) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\cli\main.py", line
73, in _main
from ..base.context import context File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\base\context.py",
line 23, in
from ..common.configuration import (Configuration, LoadError, MapParameter, PrimitiveParameter, File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 47, in
from .._vendor.toolz.functoolz import excepts File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda_vendor\toolz\functoolz.py",
line 501
f.name for f in reversed((self.first,) + self.funcs),
^ SyntaxError: Generator expression must be parenthesized
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 42, in
from cytoolz.dicttoolz import merge File "C:\Users\kaukau\Anaconda3\lib\site-packages\cytoolz__init__.py",
line 1, in
from .itertoolz import * ModuleNotFoundError: No module named 'cytoolz.itertoolz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\Scripts\conda-script.py", line 10, in
sys.exit(main()) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\cli\main.py", line
113, in main
return conda_exception_handler(_main, *args) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 1112, in conda_exception_handler
return_value = exception_handler(func, *args, **kwargs) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 822, in call
return self.handle_exception(exc_val, exc_tb) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 864, in handle_exception
return self.handle_unexpected_exception(exc_val, exc_tb) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 876, in handle_unexpected_exception
self.print_unexpected_error_report(error_report) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 932, in print_unexpected_error_report
from .base.context import context File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\base\context.py",
line 23, in
from ..common.configuration import (Configuration, LoadError, MapParameter, PrimitiveParameter, File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 47, in
from .._vendor.toolz.functoolz import excepts File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda_vendor\toolz\functoolz.py",
line 501
f.name for f in reversed((self.first,) + self.funcs),
^ SyntaxError: Generator expression must be parenthesized Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 42, in
from cytoolz.dicttoolz import merge File "C:\Users\kaukau\Anaconda3\lib\site-packages\cytoolz__init__.py",
line 1, in
from .itertoolz import * ModuleNotFoundError: No module named 'cytoolz.itertoolz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\cli\main.py", line
97, in main
from ..activate import main as activator_main File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\activate.py", line
11, in
from .base.context import ROOT_ENV_NAME, context, locate_prefix_by_name File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\base\context.py",
line 23, in
from ..common.configuration import (Configuration, LoadError, MapParameter, PrimitiveParameter, File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 47, in
from .._vendor.toolz.functoolz import excepts File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda_vendor\toolz\functoolz.py",
line 501
f.name for f in reversed((self.first,) + self.funcs),
^ SyntaxError: Generator expression must be parenthesized
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 42, in
from cytoolz.dicttoolz import merge File "C:\Users\kaukau\Anaconda3\lib\site-packages\cytoolz__init__.py",
line 1, in
from .itertoolz import * ModuleNotFoundError: No module named 'cytoolz.itertoolz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\kaukau\Anaconda3\Scripts\conda-script.py", line 10, in
sys.exit(main()) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\cli\main.py", line
110, in main
return ExceptionHandler().handle_exception(exc_val, exc_tb) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 864, in handle_exception
return self.handle_unexpected_exception(exc_val, exc_tb) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 876, in handle_unexpected_exception
self.print_unexpected_error_report(error_report) File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\exceptions.py",
line 932, in print_unexpected_error_report
from .base.context import context File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda\base\context.py",
line 23, in
from ..common.configuration import (Configuration, LoadError, MapParameter, PrimitiveParameter, File
"C:\Users\kaukau\Anaconda3\lib\site-packages\conda\common\configuration.py",
line 47, in
from .._vendor.toolz.functoolz import excepts File "C:\Users\kaukau\Anaconda3\lib\site-packages\conda_vendor\toolz\functoolz.py",
line 501
f.name for f in reversed((self.first,) + self.funcs),
^ SyntaxError: Generator expression must be parenthesized
I've just found out that I cant even use any conda commands except the : >conda --version< command only.
Please help me resolve this issue without uninstalling then reinstalling anaconda completely
Sorry to waste your time, I solved it by reinstalling anaconda completely and every project started working again....thanks to those who read it, the effort is appreciated.
It usually happen when you directly download and insall anaconda normally form its website.
Updating anaconda solved this issue for me in Manjaro and will surely work on Windows as well.
use conda update anaconda-navigator command to Update Anaconda.
If it doesn't starts, restart your pc and try to open it again.

pymysql stopped working : NameError: name 'byte2int' is not defined

I am using pymysql in Python to connect to database. It was working fine but now I am getting following error :
Traceback (most recent call last) :
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/connections.py", line 598, in connect
self._request_authentication()
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/connections.py", line 865, in _request_authentication
data = _auth.scramble_old_password(self.password, self.salt) + b'\0'
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/_auth.py", line 72, in scramble_old_password
hash_pass = _hash_password_323(password)
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/_auth.py", line 97, in _hash_password_323
for c in [byte2int(x) for x in password if x not in (' ', '\t', 32, 9)]:
File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/_auth.py", line 97, in <listcomp>
for c in [byte2int(x) for x in password if x not in (' ', '\t', 32, 9)]:
NameError: name 'byte2int' is not defined
I am using following lines to connect to my database (connection string) :
conn = pymysql.Connect(host='hostname', port=3306, user='username', passwd='password', db='mysql')
Since the pymysql maintainer refuses to release the fix, the solution is simply to install an older version of the package:
pip3 install --user 'pymysql<0.9'
I got the same error and looked like _auth.py was unable to find the reference of byte2int. I added the below line to modify _auth.py to make it work.
from util import byte2int,int2byte
Please be aware the util.py is that of pymysql as there will be util.py files in other packages as well.

AttributeError: 'module' object has no attribute 'packages'

when running test i'm getting this error.
earlier i'm using python-requests v2.2.1.so,
i have upgraded python-requests to v2.14.2 but still i'm facing the same issue.
HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict):
AttributeError: 'module' object has no attribute 'packages'check the below result:
======================================================================
ERROR: rest_blog.tests.test_views (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: rest_blog.tests.test_views
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/home/vamsi/PycharmProjects/ReminderToDo/rest_blog/tests/test_views.py", line 6, in <module>
from rest_framework.test import force_authenticate
File "/usr/local/lib/python3.4/dist-packages/rest_framework/test.py", line 30, in <module>
class HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict):
AttributeError: 'module' object has no attribute 'packages'
----------------------------------------------------------------------
Just reinstalling requests or upgrading requests should solve the problem.
pip install --upgrade requests

flask-sqlacodegen suports python 3.4?

I am trying to generate a flask-sqlalchemy for an existing mysql db.
I used the following command
flask-sqlacodegen --outfile rcdb.py mysql://username:password#hostname/tablename
The project uses python 3.4. Any clues?
```Traceback (most recent call last):
File "/var/www/devaccess/py_api/ds/venv/bin/flask-sqlacodegen", line 11, in
sys.exit(main())
File "/var/www/devaccess/py_api/ds/venv/lib/python3.4/site-packages/sqlacodegen/main.py", line 59, in main
Traceback (most recent call last):
File "/var/www/devaccess/py_api/ds/venv/bin/flask-sqlacodegen", line 11, in
sys.exit(main())
File "/var/www/devaccess/py_api/ds/venv/lib/python3.4/site-packages/sqlacodegen/main.py", line 59, in main
args.flask, ignore_cols, args.noclasses)
File "/var/www/devaccess/py_api/ds/venv/lib/python3.4/site-packages/sqlacodegen/codegen.py", line 606, in init
model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
File "/var/www/devaccess/py_api/ds/venv/lib/python3.4/site-packages/sqlacodegen/codegen.py", line 335, in init
relationship_ = ManyToManyRelationship(self.name, target_cls, association_table, inflect_engine)
File "/var/www/devaccess/py_api/ds/venv/lib/python3.4/site-packages/sqlacodegen/codegen.py", line 501, in init
self.kwargs['secondary'] = repr(assocation_table.schema + '.' + assocation_table.name)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
```
try specifying your database schema with option --schema

Resources