I have had this working, a few months ago, but apparently I phases of the moon changed or something.
I have MySQL-python installed.
And I only get this error when running manage.py shell and then trying to make db queries. When I add or remove items from the /admin/ interface then it doesn't seem to have any troubles.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 780, in execute_sql
cursor = self.connection.cursor()
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/backends/__init__.py", line 157, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/backends/__init__.py", line 129, in _cursor
self.ensure_connection()
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/backends/__init__.py", line 112, in connect
self.connection = self.get_new_connection(conn_params)
File "/home2/univetg1/python27/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 435, in get_new_connection
conn = Database.connect(**conn_params)
File "/home2/univetg1/python27/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/home2/univetg1/python27/lib/python2.7/site-packages/MySQLdb/connections.py", line 179, in __init__
client_version = tuple([ numeric_part(n) for n in _mysql.get_client_info().split('.')[:2] ])
InternalError: (-1, 'server not initialized')
my db settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}
}
Related
I'm running the following code with web3.py:
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
And I am running into the following error:
Traceback (most recent call last):
File "/Users/patrick/code/web3_py_simple_storage/deploy.py", line 64, in <module>
transaction = SimpleStorage.constructor().buildTransaction(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_utils/decorators.py", line 18, in _wrapper
return self.method(obj, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/contract.py", line 684, in buildTransaction
return fill_transaction_defaults(self.web3, built_transaction)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/_utils/transactions.py", line 121, in fill_transaction_defaults
default_val = default_getter(web3, transaction)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/_utils/transactions.py", line 71, in <lambda>
web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/eth.py", line 549, in max_priority_fee
return self._max_priority_fee()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/manager.py", line 198, in request_blocking
return self.formatted_response(response,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/manager.py", line 171, in formatted_response
raise ValueError(response["error"])
ValueError: {'message': 'Method eth_maxPriorityFeePerGas not supported.', 'code': -32000, 'data': {'stack': 'Error: Method eth_maxPriorityFeePerGas not supported.\n at GethApiDouble.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/geth_api_double.js:70:16)\n at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n at GethDefaults.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/gethdefaults.js:15:12)\n at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n at SubscriptionSubprovider.FilterSubprovider.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/subproviders/filters.js:89:7)\n at SubscriptionSubprovider.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/subproviders/subscriptions.js:137:49)\n at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n at DelayedBlockFilter.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/delayedblockfilter.js:31:3)\n at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n at RequestFunnel.handleRequest (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/subproviders/requestfunnel.js:32:12)\n at next (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:136:18)\n at Web3ProviderEngine._handleAsync (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:123:3)\n at Timeout._onTimeout (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:107:12)\n at listOnTimeout (internal/timers.js:531:17)\n at processTimers (internal/timers.js:475:7)', 'name': 'Error'}}
How do I fix this?
This is an issue from a new edition of web3.py.
You need to add gasPrice to your transaction, like so:
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "gasPrice": w3.eth.gas_price, "from": my_address, "nonce": nonce}
)
This is due to EIP1559 changing, and web3.py updating for the change.
I am going through the freeCodeCamp course on YouTube and have caught an error regarding when I run. As I am trying to build a transaction into Ganache. I see in Ganache logs that there is activity as well. First time posting, so let me know what other information should I provide!
The course: Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
The error that the terminal returns:
Traceback (most recent call last):
File "C:\Users\Justin\demos\web3_py_simple_storage\deploy.py",
line 60, in <module>
transaction = SimpleStorage.constructor().buildTransaction(
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\decorators.py", line 18, in _wrapper
return self.method(obj, *args, **kwargs)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\contract.py", line 684, in buildTransaction
return fill_transaction_defaults(self.web3, built_transaction)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\_utils\transactions.py", line 121, in fill_transaction_defaults
default_val = default_getter(web3, transaction)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\_utils\transactions.py", line 67, in <lambda>
'gas': lambda web3, tx: web3.eth.estimate_gas(tx),
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\eth.py", line 759, in estimate_gas
return self._estimate_gas(transaction, block_identifier)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\manager.py", line 197, in request_blocking
response = self._make_request(method, params)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\manager.py", line 150, in _make_request
return request_func(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\gas_price_strategy.py", line 90,
in middleware
return make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\attrdict.py", line 33, in middleware
response = make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 73, in apply_formatters
formatted_params = formatter(params)
File "cytoolz\functoolz.pyx", line 503, in cytoolz.functoolz.Compose.__call__
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\decorators.py", line 91, in wrapper
return ReturnType(result) # type: ignore
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\applicators.py", line 22, in apply_formatter_at_index
yield formatter(item)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\functional.py", line 45, in inner
return callback(fn(*args, **kwargs))
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\applicators.py", line 84, in apply_formatters_to_dict
yield key, formatters[key](item)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\applicators.py", line 72, in apply_formatter_if
return formatter(value)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\validation.py", line 57, in validate_chain_id
raise ValidationError(
web3.exceptions.ValidationError: The transaction declared chain ID 5777, but the connected node is on 1337
The Full Code that I used is below:
from solcx import compile_standard, install_solc
import json
from web3 import Web3
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
# Compile Our Solidity
print("Installing...")
install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": [
"abi",
"metadata",
"evm.bytecode",
"evm.bytecode.sourceMap",
]
}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
"bytecode"
]["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
# for connecting to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 5777
my_address = "0xf2580f5ddfFb89e69A12a7CbCa8CA175Df4cBe08"
private_key = "0x937073896304af4297e6bbb3a3c623689d48388aa8595058752fafb522b31a13"
# Create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
print(SimpleStorage)
# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
# 1. Build a transaction
# 2. Sign a transaction
# 3. Send a transaction
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
print(transaction)
As of 5.25.0 of web3.py, we now need to add gasPrice to our transactions with a local Ganache chain. Adding "gasPrice": w3.eth.gas_price should fix your issue in the transactions.
Full Example:
transaction = SimpleStorage.constructor().buildTransaction(
{
"chainId": chain_id,
"gasPrice": w3.eth.gas_price,
"from": my_address,
"nonce": nonce,
}
)
Use the following line in .buildTransaction:
transaction = SimpleStorage.constructor().buildTransaction(
{'from': address, 'nonce':nonce, 'chainId':chain_id,'gas': 1728712,
'gasPrice': w3.toWei('21', 'gwei')})
And change the chain_id = 1337.
The transaction declared chain ID 5777, but the connected node is on 1337.
You have to change your chain_id:
chain_id = 5777❌
But use the one below
chain_id = 1337✔
I was having this exact same problem. Including "gasPrice": w3.eth.gas_price, solved it originally, but it came back.
After some tweaking, I found that casting chain_id (because I was getting that from .env as well) as an int solved my problems.
So the full code looked like this:
transaction = SimpleStorage.constructor().buildTransaction(
{
"chainId": int(chain_id),
"gasPrice": w3.eth.gas_price,
"from": my_address,
"nonce": nonce,
}
)
I recently added the mycase app to my larger django project but since then I have been getting all kinds of database errors. If any more information would be helpful just reply with a comment, I don't know exactly what would be helpful in this case. Thanks!
Traceback:
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/opt/anaconda3/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/opt/anaconda3/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/anaconda3/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/anaconda3/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/anaconda3/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/opt/anaconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/andrew/Desktop/Projects/purplerobotics/purplerobotics/urls.py", line 23, in <module>
path('case/', include('mycase.urls'))
File "/opt/anaconda3/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/opt/anaconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/andrew/Desktop/Projects/purplerobotics/mycase/urls.py", line 2, in <module>
from . import views
File "/Users/andrew/Desktop/Projects/purplerobotics/mycase/views.py", line 7, in <module>
class CaseHome(ListView):
File "/Users/andrew/Desktop/Projects/purplerobotics/mycase/views.py", line 10, in CaseHome
total_price = CaseItem.objects.all().aggregate(total=Sum(F('Item_Price')*F('Item_Quantity')))['total']
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/models/query.py", line 398, in aggregate
return query.get_aggregation(self.db, kwargs)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/models/sql/query.py", line 500, in get_aggregation
result = compiler.execute_sql(SINGLE)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: mycase_caseitem
Project Settings File:
from pathlib import Path
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'theblog',
'dashboard',
'mycase'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'purplerobotics.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'purplerobotics.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
mycase models.py file
from django.db import models
from django.urls import reverse
# Create your models here.
class CaseItem(models.Model):
Item_Title = models.CharField(max_length=200)
Item_Price = models.DecimalField(default=0, max_digits=10, decimal_places=2)
Item_Quantity = models.DecimalField(default=0, max_digits=10, decimal_places=2)
def __str__(self):
return self.Item_Title + ' | ' + str(self.Item_Quantity) + ' * $' + str(self.Item_Price)
def get_absolute_url(self):
return reverse('home')
If anything else would be helpful I would be happy to get it.
Once you are done with your model, you have to run migrations - this handles the database processes, in this case the creation of the table.
so:
python manage.py makemigrations
and
python manage.py migrate
I have these methods:
#api.depends('order_lines', 'order_lines.isbn')
def _get_products(self):
isbn = self.env['product.product']
for prodtmpl in self.order_lines:
isbn |= prodtmpl.isbn
return isbn
#api.model
def _get_act_window_dict(self, name):
mod_obj = self.env['ir.model.data']
result = mod_obj.xmlid_to_object(name)
if not result:
result = {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'stock.quant',
'name': 'Stock On Hand',
'type': 'ir.actions.act_window',
}
else:
result = result[0].read()[0]
return result
#api.multi
def action_open_isbn(self):
isbn = self._get_products()
result = self._get_act_window_dict('stock.product_open_quants')
result['domain'] = "[('isbn','in',[" + ','.join(map(str, isbn.ids)) + "])]"
result['context'] = "{'search_default_locationgroup': 1, 'search_default_internal_loc': 1}"
return result
On method get_act_window_dict it should return products on quants, like on Qty On Hand from product.template
But it throws me this:
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 944, in call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\stock\stock.py", line 331, in read_group
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 2082, in read_group
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 4498, in _where_calc
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\osv\expression.py", line 662, in __init__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\osv\expression.py", line 830, in parse
ValueError: Invalid field u'isbn' in leaf "<osv.ExtendedLeaf: (u'isbn', u'in', [59]) on stock_quant (ctx: )>"
I've tried doing this:
#api.model
def _get_act_window_dict(self, name):
mod_obj = self.env['ir.model.data']
result = mod_obj.xmlid_to_object(name)
if not result:
result = {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'stock.quant',
'name': 'Stock On Hand',
'isbn': 'product_id',
'type': 'ir.actions.act_window',
}
else:
result = result[0].read()[0]
return result
Adding isbn to the dict result as product_id but same result.
So, any ideas?
PS: This is isbn field on my class:
isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
Of course it doesn't exist as isbn on stock.quant but it's a Many2one to product so it should pass somehow.
This line:
result['domain'] = "[('isbn','in',[" + ','.join(map(str, isbn.ids)) + "])]"
should be:
result['domain'] = "[('product_id','in',[" + ','.join(map(str, isbn.ids)) + "])]"
No field isbn in stock.quant. Since isbn is object product.product, I think it's just the same with product_id of stock.quant
My neutronTest.py file
import getpass
from neutronclient.v2_0 import client
username = '#myUserName#'
password1 = getpass.getpass()
tenant_name = '#myTenantName#'
auth_url = 'https://keystone.#mydomain#.fr:5000/v3'
neutron = client.Client(username=username,
password = password1,
tenant_name = tenant_name,
auth_url = auth_url,
)
netw = neutron.list_networks()
print(netw)
Its gives me this Error :
The Error :
Traceback (most recent call last):
File "pythonTest.py", line 17, in <module>
netw=neutron.list_networks()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 640, in list_networks
**_params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 357, in list
for r in self._pagination(collection, path, **params):
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 372, in _pagination
res = self.get(path, params=params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 342, in get
headers=headers, params=params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 319, in retry_request
headers=headers, params=params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 270, in do_request
resp, replybody = self.httpclient.do_request(action, method, body=body)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 158, in do_request
self.authenticate_and_fetch_endpoint_url()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 123, in authenticate_and_fetch_endpoint_url
self.authenticate()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 237, in authenticate
self._authenticate_keystone()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 218, in _authenticate_keystone
raise exceptions.Unauthorized(message=resp_body)
neutronclient.common.exceptions.Unauthorized: {"error": {"message": "The resource could not be found.", "code": 404, "title": "Not Found"}}
I think because I have a v3 keystone version, but I still don't know how to solve the problem.
Thank you for your help!