Django registration error after switching interpreter to Python 2.78 - django

I initially had python 3.4 installed with django 1.65. But i searched and found out Django registration doesn't work with python 3. So I downloaded python 2.78 and even uninstalled python 3.4.
However When i am on url http://www.localhost:8000/accounts/register/ and try to register a user an error comes up. It seems like its django registration is still reading my old virtual env linked to python 3.4 and its path. I have edited my environmental variable PATH to delete any Python 3.4 and replaced with Python 2.7. But still same error occurs. I'm new to web development. Sorry if I didn't provide enough detail or to little detail.
TypeError at /accounts/register/
Unicode-objects must be encoded before hashing
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/
Django Version: 1.6.5
Exception Type: TypeError
Exception Value:
Unicode-objects must be encoded before hashing
Exception Location: C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\models.py in create_profile, line 106
Python Executable: C:\Users\jasan\virtual_enc_matchmaker\Scripts\pythonw.exe
Python Version: 3.4.1
Python Path:
['C:\\Users\\jasan\\PycharmProjects\\matchmaker',
'C:\\Users\\jasan\\PycharmProjects\\matchmaker',
'C:\\WINDOWS\\SYSTEM32\\python34.zip',
'C:\\Python34\\DLLs',
'C:\\Python34\\lib',
'C:\\Python34',
'C:\\Users\\jasan\\virtual_enc_matchmaker',
'C:\\Users\\jasan\\virtual_enc_matchmaker\\lib\\site-packages']
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/
Django Version: 1.6.5
Python Version: 3.4.1
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'profiles',
'south',
'registration',
'PIL',
'stripe')
Installed Middleware:
('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')
Traceback:
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\django\core\handlers\base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\django\views\generic\base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\views.py" in dispatch
79. return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\django\views\generic\base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\views.py" in post
35. return self.form_valid(request, form)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\views.py" in form_valid
82. new_user = self.register(request, **form.cleaned_data)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\backends\default\views.py" in register
80. password, site)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\django\db\transaction.py" in inner
431. return func(*args, **kwargs)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\models.py" in create_inactive_user
88. registration_profile = self.create_profile(new_user)
File "C:\Users\jasan\virtual_enc_matchmaker\lib\site-packages\registration\models.py" in create_profile
106. salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
Exception Type: TypeError at /accounts/register/
Exception Value: Unicode-objects must be encoded before hashing

Related

How generate a pdf file with django-wkhtmltopdf on IIS 7.5 - 8

I use django-wkhtmltopdf to generate pdfs in my webapp, Works fine using the django integrate server, but when I use IIS 7.5 or 8 gives me this error: WindowsError [Error 6] The handle is invalid
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8006/blabla/pdf/10/
Django Version: 1.8.5
Python Version: 2.7.10
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'NuevoTicket',
'crispy_forms',
'wkhtmltopdf',
'ckeditor',
'ckeditor_uploader')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
164. response = response.render()
File "C:\Python27\lib\site-packages\django\template\response.py" in render
158. self.content = self.rendered_content
File "C:\Python27\lib\site-packages\wkhtmltopdf\views.py" in rendered_content
78. cmd_options=cmd_options
File "C:\Python27\lib\site-packages\wkhtmltopdf\utils.py" in render_pdf_from_template
159. cmd_options=cmd_options)
File "C:\Python27\lib\site-packages\wkhtmltopdf\utils.py" in convert_to_pdf
121. return wkhtmltopdf(pages=[filename], **cmd_options)
File "C:\Python27\lib\site-packages\wkhtmltopdf\utils.py" in wkhtmltopdf
109. return check_output(ck_args, **ck_kwargs)
File "C:\Python27\lib\subprocess.py" in check_output
566. process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "C:\Python27\lib\subprocess.py" in __init__
702. errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
File "C:\Python27\lib\subprocess.py" in _get_handles
857. errwrite = _subprocess.GetStdHandle(_subprocess.STD_ERROR_HANDLE)
Exception Type: WindowsError at /blabla/pdf/10/
Exception Value: 6 The handle is invalid
Finally got it, thank's to n1b0r. I have to update the check_out method in python27/lib/subprocess.py like this
from:
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = Popen(stdout=PIPE, *popenargs, **kwargs)
to:
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
kwargs.pop('stderr', None)
process = Popen(stdout=PIPE, stderr=PIPE, stdin=PIPE, *popenargs, **kwargs)
That make it works in IIS but gives an error if use the django integrate server.
I used to have the same problem. Add the option quiet to the pdfkit and also try to modify the file configuration.py from pdfkit
options = {'quiet': ''}
pdfkit.from_file('in.html', 'out.pdf',options = options)
configuration.py
from this:
self.wkhtmltopdf = subprocess.Popen(['where','wkhtmltopdf'],stdout=subprocess.PIPE).communicate()[0].strip()
to:
self.wkhtmltopdf = subprocess.Popen(['which','wkhtmltopdf'],stdin=subprocess.PIPE,stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0].strip()

TypeError in Django after attempting to write data to MySQL using Django Models

I am trying to write data to MySQL DB using models in django but I am getting TypeError. I have failed to identify the problem. I have attached the errot summary, traceback and the lines of code generating the bug. Please help me identify the problem
TypeError at /httptester/670747/
'str' object is not callable
Request Method: POST Request URL: http://127.0.0.1:8000/httptester/670747/ Django Version: 1.5.12 Exception Type: TypeError Exception Value:
'str' object is not callable
Exception Location: /home/ronchino/deltasms/entry.py in handle, line 59 Python Executable: /home/ronchino/deltasms-venv/bin/python Python Version: 2.7.3 Python Path:
['/home/ronchino/deltasms', '/home/ronchino/deltasms-venv/lib/python2.7', '/home/ronchino/deltasms-venv/lib/python2.7/plat-linux2', '/home/ronchino/deltasms-venv/lib/python2.7/lib-tk', '/home/ronchino/deltasms-venv/lib/python2.7/lib-old', '/home/ronchino/deltasms-venv/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages']
Server time: Mon, 26 Jan 2015 10:14:12 -0600
TRACEBACK Environment:
Request Method: POST Request URL: http://127.0.0.1:8000/httptester/670747/
Django Version: 1.5.12 Python Version: 2.7.3 Installed Applications: ('model', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django_nose', 'django_tables2', 'selectable', 'south', 'rapidsms', 'rapidsms.backends.database', 'rapidsms.contrib.handlers', 'rapidsms.contrib.httptester', 'rapidsms.contrib.messagelog', 'rapidsms.contrib.messaging', 'rapidsms.contrib.registration', 'rapidsms.contrib.default') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback: File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
113. response = callback(request, *callback_args, **callback_kwargs) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
25. return view_func(request, *args, **kwargs) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/contrib/httptester/views.py" in message_tester
70. storage.store_and_queue(identity, cd["text"]) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/contrib/httptester/storage.py" in store_and_queue
39. receive(text, connection) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/router/api.py" in receive
40. router.receive_incoming(message) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/router/blocking/router.py" in receive_incoming
124. self.process_incoming(msg) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/router/blocking/router.py" in process_incoming
135. continue_processing = self.process_incoming_phases(msg) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/router/blocking/router.py" in process_incoming_phases
165. handled = func(msg) File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/contrib/handlers/app.py" in handle
33. if handler.dispatch(self.router, msg): File "/home/ronchino/deltasms-venv/local/lib/python2.7/site-packages/rapidsms/contrib/handlers/handlers/pattern.py" in dispatch
74. cls(router, msg).handle(*match.groups()) File "/home/ronchino/deltasms/entry.py" in handle
59. p2 = entry(full_name=fullname.title(), mobile_number=sender, address=address.title(), citytown=cityortown.title(), creation_datetime=date, combination=combination, entry_code=entryref)
Exception Type: TypeError at /httptester/670747/ Exception Value: 'str' object is not callable
CODE:
entry = '%32x' % random.getrandbits(32*5)
entryref = 'ENT' + entry[2] + entry [4] + entry[6] + entry[8] + entry [10] + entry[12] + entry[14] + entry [16] + entry[18] + entry[20]
#Add entry
try:
p2 = entry(full_name=fullname.title(), mobile_number=sender, address=address.title(), citytown=cityortown.title(), creation_datetime=date, combination=combination, entry_code=entryref)
p2.save()

<Model> matching query does not exist

I've learned python django since three days ago .
I wanted to remove an field from model, so I put the '#' front of that field.
Then I started the server again, but it gave me such an error message
'Userprofile matching query does not exist' (Userprofile is the model which I made.)
How can I solve this problem. I'm just a totally new to django, so even it's not easy to question my problem. If the clue is not enough, please tell me what other information is need.
p.s here is the total error message.
Environment:
Request Method: GET
Request URL: h ttp://localhost:8000/
Django Version: 1.6.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'south',
'autocomplete_light',
'djcelery',
'asap_web',
'facebook',
'venue',
'notification',
'study',
'general',
'member',
'advertise')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in __call__
89. return main()
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in main
25. return process_request()
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in process_request
53. return _call_proper_request_processor()
File "/home/jaehoon/PycharmProjects/studysearch/asap_web/__init__.py" in _call_proper_request_processor
77. return getattr(self, method_name)(request, *self.args, **kwargs)
File "/home/jaehoon/PycharmProjects/studysearch/general/views.py" in process_get_request
19. if user.is_authenticated() and user.get_profile().is_required_more_info:
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in get_profile
441. self._state.db).get(user__id__exact=self.id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in get
307. self.model._meta.object_name)
Exception Type: DoesNotExist at /
Exception Value: UserProfile matching query does not exist.
The exception is DoesNotExist which is thrown when you use get to retrieve single instance but it does not exist. In your process_get_request view:
user.get_profile().is_required_more_info
is throwing this exception because there is no profile created for this user. Note that user.get_profile() is deprecated since django 1.5 and you should use OneToOne field or custom user model instead, from docs:
get_profile() Deprecated in Django 1.5: Deprecated since version 1.5:
With the introduction of custom User models, the use of
AUTH_PROFILE_MODULE to define a single profile model is no longer
supported. See the Django 1.5 release notes for more information.

Site matching query does not exist. Lookup parameters were {'pk': 3}

Environment:
Request Method: GET
Django Version: 1.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.linkedin',
'django.contrib.admin',
'django.contrib.admindocs')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/var/www/sampleapp/allauth/account/views.py" in dispatch
41. **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/edit.py" in get
155. return self.render_to_response(self.get_context_data(form=form))
File "/var/www/sampleapp/allauth/account/views.py" in get_context_data
67. "site": Site.objects.get_current(),
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py" in get_current
26. current_site = self.get(pk=sid)
File "/usr/local/lib/python2.7/dist-packages/django/d
b/models/manager.py" in get
143. return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in get
401. (self.model._meta.object_name, kwargs))
Exception Type: DoesNotExist at /accounts/login/
Exception Value: Site matching query does not exist. Lookup parameters were {'pk': 3}
I am new to django,
Help me to fix this issue?
I encountered this problem as well. I was going through the PyCharm Django guide. I fixed this by deleting my sqlite database file and running syncdb again. I don't know why it didn't work the first time, but it works now.
Also, it's probably worth downloading the SQLite Database Browser so that you can see the actual structure of your SQLite database. For this issue, you're interested in the django_site table. After I deleted my database file and reran syncdb, there was one row in this table.
This problem occurs because the first time that you executes python manage.py syncdb. isn't specified a main user. To solve it, delete all tables created by django in data base (with mysql, postgresql..) or delete the database.db (with sqlite3), Then run python manage.py syncdb one more time

ViewDoesNotExist at /accounts/register/ (django-registration-me error)

I am currently working on a project which uses mongoengine and django. I am using django-registration-me to handle user registrations, but I am having problems after submitting the new user registration form.
The error I am receiving is:
"ViewDoesNotExist at /accounts/register/" "Tried settings in module
core.views. Error was: 'module' object has no attribute 'settings'"
It sends a verification email out fine though. I am new to django and mongoengine, so any help with this would be greatly appreciated.
The traceback is below.
Environment:
Request Method: POST Request URL:
http://dev.teamfit.us:8000/accounts/register/
Django Version: 1.3 beta 1 SVN-15207
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'registration']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File
"/usr/src/django-trunk/django/core/handlers/base.py"
in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File
"/usr/local/lib/python2.6/dist-packages/django_registration_me-0.7-py2.6.egg/registration/views.py"
in register
153. return HttpResponseRedirect(success_url or
reverse('registration_complete'))
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in reverse
390. *args, **kwargs)))
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in reverse
311. possibilities = self.reverse_dict.getlist(lookup_view)
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in _get_reverse_dict
228. self._populate()
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in _populate
219. lookups.appendlist(pattern.callback,
(bits, p_pattern))
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in _get_callback
169. raise ViewDoesNotExist("Tried %s in module
%s. Error was: %s" % (func_name,
mod_name, str(e)))
Exception Type: ViewDoesNotExist at
/accounts/register/
Exception Value: Tried settings in
module core.views. Error was: 'module'
object has no attribute 'settings'
I guess, you have
import settings
or some such variation in your code.
You should change it to:
from django.conf import settings
and it should work