Sunday, April 3, 2011

unicode and database oddity

Hi, sorry for the long message to follow, but I have an odd issue with
inserting a value into my database (MySQL).
In short, I am grabbing in a url as a variable fed in via urls.py and
am getting that value as a unicode.
Even if I convert this with smart_str and it's type is then string, I
still raise a unicode error when trying to input this into my
database.

I have attached some error output from the 500 error being raised, as
well as some code from a shell session that I think more clearly shows
my issue.

Any assistance would be greatly appreciated. Thanks in advance!

Environment:

Request Method: GET
Request URL:
http://192.168.11.4:8001/url/http://forecast.weather.gov/MapClick.php?CityName=Philadelphia&state=PA&site=PHI&lat=39.9525&lon=-75.1657/

Django Version: 1.3 SVN-16009
Python Version: 2.6.5
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', 'shortener']
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 "/home/mugen/programming/django/django/core/handlers/base.py" in
get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/mugen/programming/Stumpy/shortener/views.py" in submit
19. thisurl = url(longurl=theurl)

Exception Type: TypeError at /url/http://forecast.weather.gov/
MapClick.php
?
CityName=Philadelphia&state=PA&site=PHI&lat=39.9525&lon=-75.1657/
Exception Value: 'unicode' object is not callable

from shortener.models import url
url = u'http://t04u.be/'
type(url)

b = url(longurl=url)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable
from django.utils.encoding import smart_str
b = url(longurl=smart_str(url))
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable
smart_str(url)
'http://t04u.be/'
type(smart_str(url))

a = smart_str(url)
type(a)

b = url(longurl=a)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment