Getting 'DatabaseError' object has no attribute 'message' in DJango - django

I am trying to run the following code here to save information to the database. I have seen other messages - but - it appears that the solutions are for older versions of Python/DJango (as they do not seem to be working on the versions I am using now: Python 3.6.3 and DJango 1.11.7
if form.is_valid():
try:
item = form.save(commit=False)
item.tenantid = tenantid
item.save()
message = 'saving data was successful'
except DatabaseError as e:
message = 'Database Error: ' + str(e.message)
When doing so, I get an error message the error message listed below. How can I fix this so I can get the message found at the DB level printed out?
'DatabaseError' object has no attribute 'message'
Request Method:
POST
Request URL:
http://127.0.0.1:8000/storeowner/edit/
Django Version:
1.11.7
Exception Type:
AttributeError
Exception Value:
'DatabaseError' object has no attribute 'message'
Exception Location:
C:\WORK\AppPython\ContractorsClubSubModuleDEVELOP\libmstr\storeowner\views.py in edit_basic_info, line 40
Python Executable:
C:\WORK\Software\Python64bitv3.6\python.exe
Python Version:
3.6.3
Python Path:
['C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP',
'C:\\WORK\\Software\\OracleInstantClient64Bit\\instantclient_12_2',
'C:\\WORK\\Software\\Python64bitv3.6\\python36.zip',
'C:\\WORK\\Software\\Python64bitv3.6\\DLLs',
'C:\\WORK\\Software\\Python64bitv3.6\\lib',
'C:\\WORK\\Software\\Python64bitv3.6',
'C:\\Users\\dgmufasa\\AppData\\Roaming\\Python\\Python36\\site-packages',
'C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP\\libintgr',
'C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP\\libmstr',
'C:\\WORK\\AppPython\\ContractorsClubSubModuleDEVELOP\\libtrans',
'C:\\WORK\\AppPython\\ContractorsClubBackofficeCode\\libintgr',
'C:\\WORK\\AppPython\\ContractorsClubBackofficeCode\\libmstr',
'C:\\WORK\\TRASH\\tempforcustomer\\tempforcustomer\\libtempmstr',
'C:\\WORK\\AppPython\\ContractorsClubBackofficeCode\\libtrans',
'C:\\WORK\\Software\\Python64bitv3.6\\lib\\site-packages',
'C:\\WORK\\Software\\Python64bitv3.6\\lib\\site-packages\\django-1.11.7-py3.6.egg',
'C:\\WORK\\Software\\Python64bitv3.6\\lib\\site-packages\\pytz-2017.3-py3.6.egg']
Server time:
Sat, 9 Dec 2017 08:42:49 +0000

Just change
str(e.message)
to
str(e)

some change
str(e.message)
to
HttpResponse(e.message)

Related

Python 3.7 AttributeError: 'str' object has no attribute 'has'

Using Python 3.7.3 , PIP 19.3.1 , Django 2.2, I need to check whether an object is string or not and started by using this code:
if not isinstance(math, basestring):
math = latex(math)
return '<script type="math/tex; mode=display">{}</script>'.format(math)
Using 'str' instead of 'basestring' causes the script to output an error:
'str' object has no attribute 'get' error
I then tried the following code
def format_math_display(self, math):
try:
if not isinstance(math, basestring):
math = latex(math)
return '<script type="math/tex; mode=display">{}
</script>'.format(math)
except Exception:
pass
But it also leads to an(other) error:
AttributeError at /
'str' object has no attribute 'has'
Request Method: POST
Request URL: http://127.0.0.1:8000/
Django Version: 2.2.6
Exception Type: AttributeError
Exception Value: 'str' object has no attribute 'has'
Python Executable: C:\Users\Vasundhara\Envs\calculate\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\wamp64\\www\\Python3Django2\\Calculate',
'C:\\Users\\Vasundhara\\Envs\\calculate\\Scripts\\python37.zip',
'C:\\Users\\Vasundhara\\Envs\\calculate\\DLLs',
'C:\\Users\\Vasundhara\\Envs\\calculate\\lib',
'C:\\Users\\Vasundhara\\Envs\\calculate\\Scripts',
'c:\\users\\vasundhara\\appdata\\local\\programs\\python\\python37\\Lib',
'c:\\users\\vasundhara\\appdata\\local\\programs\\python\\python37\\DLLs',
'C:\\Users\\Vasundhara\\Envs\\calculate',
'C:\\Users\\Vasundhara\\Envs\\calculate\\lib\\site-packages']
Server time: Sat, 26 Oct 2019 04:08:58 +0000
What am I missing here?

Django HttpResponseRedirect and NoReverseMatch

I am trying to redirect to a new form page whose fields get automatically filled with the data sent from the view function.
My urls.py is:
url(r"user_dashboard/NewRequest/([\{.*\}])", views.request_form, name = "NewRequest")
The view function which is sending the data is present at:
url(r"user_dashboard/NReq", views.request_request, name="NReq"),
which calls the above url.
The return statement from my view function is:
return HttpResponseRedirect(reverse(request_form, kwargs={"device_type":devicetype}))
But, I get the following error:
NoReverseMatch at /user_dashboard/NReq
Reverse for 'inventory_management_app.views.request_form' with keyword arguments '{u'device_type': u'Laptop'}' not found. 1 pattern(s) tried: ['user_dashboard/NewRequest/([\\{.*\\}])']
Request Method: POST
Request URL: http://127.0.0.1:8000/user_dashboard/NReq
Django Version: 1.11.13
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'inventory_management_app.views.request_form' with keyword arguments '{u'device_type': u'Laptop'}' not found. 1 pattern(s) tried: ['user_dashboard/NewRequest/([\\{.*\\}])']
Exception Location: C:\Anaconda2\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 497
Python Executable: C:\Anaconda2\python.exe
Python Version: 2.7.14
Python Path:
['E:\\inventory management\\inventory_management_service',
'C:\\Anaconda2\\python27.zip',
'C:\\Anaconda2\\DLLs',
'C:\\Anaconda2\\lib',
'C:\\Anaconda2\\lib\\plat-win',
'C:\\Anaconda2\\lib\\lib-tk',
'C:\\Anaconda2',
'C:\\Users\\Jaimik Jain\\AppData\\Roaming\\Python\\Python27\\site-packages',
'C:\\Anaconda2\\lib\\site-packages',
'C:\\Anaconda2\\lib\\site-packages\\win32',
'C:\\Anaconda2\\lib\\site-packages\\win32\\lib',
'C:\\Anaconda2\\lib\\site-packages\\Pythonwin',
'C:\\Anaconda2\\lib\\site-packages\\pywinpty-0.5-py2.7-win-amd64.egg']
Server time: Wed, 6 Jun 2018 07:48:44 +0000
Can anyone please tell me what's wrong present in the above code?
Instead of the following regex expression url(r"user_dashboard/NewRequest/([\{.*\}])", views.request_form, name = "NewRequest") in your URL:
try with re group name:
url(r"user_dashboard/NewRequest/(?P<device_name>\w.+)", views.request_form, name = "NewRequest")
Make sure you have device_name as a default argument in your view
def request_form(request,device_name=''):
'''

i have two projects in django i can not open admin site for my second project,but i can open for my first project,can any one help me

AttributeError at /admin/
'WSGIRequest' object has no attribute 'user'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 2.0.2
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'user'
Exception Location: C:\Users\vaaz\Desktop\venv\lib\site-packages\django\contrib\admin\sites.py in has_permission, line 186
Python Executable: C:\Users\vaaz\Desktop\venv\Scripts\python.exe
Python Version: 3.4.3
Python Path:
['C:\Users\vaaz\website1',
'C:\Windows\system32\python34.zip',
'C:\Users\vaaz\Desktop\venv\DLLs',
'C:\Users\vaaz\Desktop\venv\lib',
'C:\Users\vaaz\Desktop\venv\Scripts',
'C:\Python34\Lib',
'C:\Python34\DLLs',
'C:\Users\vaaz\Desktop\venv',
'C:\Users\vaaz\Desktop\venv\lib\site-packages']
Server time: Mon, 12 Mar 2018 10:21:49 +0000
This looks similar to this post
with your limited error description I can only suggest a few things that were mentioned in the above post:
Older Django versions use MIDDLEWARE_CLASSES = (...) in the settings.py rather than MIDDLEWARE = (...) try changing that variable.
If you are using virtualenv be sure to activate it before trying to runserver
If you created your app in a different version of Django and then installed it on another version it might give you errors.

Error in testing part of my django poll app

I get the following error in my django poll app. I do not understand what it states, can anyone suggest me what to do? Any solution to this?
NameError at / name 'model' is not defined
Request Method: GET Request URL: http://127.0.0.1:8000/
Django Version: 1.8.6
Exception Type: NameError
Exception Value: name 'model' is not defined
Exception Location: c:\Anaconda-installation\mysite\polls\views.py in ResultView, line 26
Python Executable: C:\Anaconda-installation\python.exe
Python Version: 2.7.10
Python Path: ['c:\\Anaconda-installation\\mysite',
'C:\\Anaconda-installation\\python27.zip',
'C:\\Anaconda-installation\\DLLs',
'C:\\Anaconda-installation\\lib',
'C:\\Anaconda-installation\\lib\\plat-win',
'C:\\Anaconda-installation\\lib\\lib-tk',
'C:\\Anaconda-installation',
'c:\\anaconda-installation\\lib\\site-packages\\sphinx-1.3.1-py2.7.egg',
'c:\\anaconda-installation\\lib\\site-packages\\setuptools-17.1.1-py2.7.egg',
'C:\\Anaconda-installation\\lib\\site-packages',
'C:\\Anaconda-installation\\lib\\site-packages\\cryptography-0.9.1-py2.7-win-amd64.egg',
'C:\\Anaconda-installation\\lib\\site-packages\\win32',
'C:\\Anaconda-installation\\lib\\site-packages\\win32\\lib',
'C:\\Anaconda-installation\\lib\\site-packages\\Pythonwin']
Server time: Tue, 8 Dec 2015 04:49:21 +0000

'WSGIRequest' object has no attribute 'id' - Django Oscar Paypal?

Trying to integrate Django-Oscar-Paypal with my project. I'm using Paypal express version. On checkout the flow is going to Paypal's site. But when the Paypal redirects back to my site I'm getting the following error.
AttributeError at /checkout/paypal/preview/16/
'WSGIRequest' object has no attribute 'id'
Request Method: GET
Request URL: http://localhost:8000/checkout/paypal/preview/16/?token=EC-9JB96808VX198132S&PayerID=TYNFGLXS46S2E
Django Version: 1.8.3
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'id'
Exception Location: /Users/nikhilsingh/djangoOscarEnv/lib/python2.7/site-packages/oscar/apps/offer/applicator.py in get_basket_offers, line 93
Python Executable: /Users/nikhilsingh/djangoOscarEnv/bin/python
Python Version: 2.7.6
Python Path:
['/Users/nikhilsingh/teabox_new/teashop',
'/Users/nikhilsingh/djangoOscarEnv/lib/python27.zip',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/plat-darwin',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/plat-mac',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/nikhilsingh/djangoOscarEnv/Extras/lib/python',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/lib-tk',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/lib-old',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/nikhilsingh/djangoOscarEnv/lib/python2.7/site-packages']
Server time: Mon, 5 Oct 2015 07:10:10 +0000
It seems like the basket gets empty on redirection hence no id is found. What can I do to resolve this issue ?