invalid literal for int() with base 10 trying to access uploaded image

842 views
Skip to first unread message

silk.odyssey

unread,
Sep 18, 2008, 8:17:22 AM9/18/08
to Django users
I am using an imagefield from the admin interface. I can upload images
without problems but when I click the link to view the image, I get
the following error.

invalid literal for int() with base 10: '1/photos/desktop.png'

Any idea what's wrong? I am using django 1.0.

Picio

unread,
Sep 18, 2008, 9:34:58 AM9/18/08
to django...@googlegroups.com
I have the same issue, tried:
Django 1.0 with sqlite3 (Wiindows)
Django 1.0 with Mysql 5.0 (Windows)
Django 1.0 with sqlite3 (Mac OS X)

Daniele

2008/9/18 silk.odyssey <silko...@gmail.com>:

Ross

unread,
Sep 18, 2008, 9:47:43 AM9/18/08
to Django users
The error looks like you are passing '1/photos/desktop.png' to int(),
which converts a string to an integer. How are you creating the link
to the picture?

Your urls.py could be capturing that entire string and passing it as a
parameter that you are trying to cast to an integer.

A bigger stack trace would be easier to track down the problem.

On Sep 18, 8:34 am, Picio <picios...@gmail.com> wrote:
> I have the same issue, tried:
> Django 1.0 with sqlite3 (Wiindows)
> Django 1.0 with Mysql 5.0 (Windows)
> Django 1.0 with sqlite3 (Mac OS X)
>
> Daniele
>
> 2008/9/18 silk.odyssey <silkodys...@gmail.com>:

kelvin pompey

unread,
Sep 18, 2008, 10:15:09 AM9/18/08
to django...@googlegroups.com
Everything is being handled by the admin application.

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/grades/student/1/photos/desktop.png/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'sgms.grades']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
  158.                 return self.model_page(request, *url.split('/', 2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in model_page
  177.         return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in __call__
  197.             return self.change_view(request, unquote(url))
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success
  238.                 res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
  557.             obj = model._default_manager.get(pk=object_id)
File "/usr/lib/python2.5/site-packages/django/db/models/manager.py" in get
  93.         return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in get
  297.         clone = self.filter(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in filter
  483.         return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _filter_or_exclude
  501.             clone.query.add_q(Q(*args, **kwargs))
File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py" in add_q
  1224.                             can_reuse=used_aliases)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py" in add_filter
  1167.         self.where.add((alias, col, field, lookup_type, value), connector)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/where.py" in add
  48.                 params = field.get_db_prep_lookup(lookup_type, value)
File "/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
  202.             return [self.get_db_prep_value(value)]
File "/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  353.         return int(value)

Exception Type: ValueError at /admin/grades/student/1/photos/desktop.png/
Exception Value: invalid literal for int() with base 10: '1/photos/desktop.png'

Picio

unread,
Sep 18, 2008, 10:16:13 AM9/18/08
to django...@googlegroups.com
It happens inside the admin interface, so I've little control on It (AFAIK).
This what i have in my urls.py:

from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root),
)

I've pasted a traceback on dpaste.com

2008/9/18 Ross <rea...@gmail.com>:

Picio

unread,
Sep 18, 2008, 10:17:34 AM9/18/08
to django...@googlegroups.com
Here is mine, since I don't know how to reference dpaste... ;)
Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/tvsite/areas/1/areas/batzos.jpeg/


Django Version: 1.0-final-SVN-unknown
Python Version: 2.5.2
Installed Applications:

['django.contrib.admin',


'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',

'tv.tvsite']


Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python25\Lib\site-packages\django\core\handlers\base.py" in


get_response
86. response = callback(request, *callback_args,
**callback_kwargs)

File "C:\Python25\Lib\site-packages\django\contrib\admin\sites.py" in root


158. return self.model_page(request, *url.split('/', 2))

File "C:\Python25\lib\site-packages\django\views\decorators\cache.py"


in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)

File "C:\Python25\Lib\site-packages\django\contrib\admin\sites.py" in model_page
177. return admin_obj(request, rest_of_url)
File "C:\Python25\Lib\site-packages\django\contrib\admin\options.py" in __call__
197. return self.change_view(request, unquote(url))
File "C:\Python25\Lib\site-packages\django\db\transaction.py" in


_commit_on_success
238. res = func(*args, **kw)

File "C:\Python25\Lib\site-packages\django\contrib\admin\options.py"


in change_view
557. obj = model._default_manager.get(pk=object_id)

File "C:\Python25\Lib\site-packages\django\db\models\manager.py" in get
93. return self.get_query_set().get(*args, **kwargs)
File "C:\Python25\Lib\site-packages\django\db\models\query.py" in get


297. clone = self.filter(*args, **kwargs)

File "C:\Python25\Lib\site-packages\django\db\models\query.py" in filter


483. return self._filter_or_exclude(False, *args, **kwargs)

File "C:\Python25\Lib\site-packages\django\db\models\query.py" in
_filter_or_exclude
501. clone.query.add_q(Q(*args, **kwargs))
File "C:\Python25\Lib\site-packages\django\db\models\sql\query.py" in add_q
1224. can_reuse=used_aliases)
File "C:\Python25\Lib\site-packages\django\db\models\sql\query.py" in add_filter


1167. self.where.add((alias, col, field, lookup_type,
value), connector)

File "C:\Python25\Lib\site-packages\django\db\models\sql\where.py" in add


48. params = field.get_db_prep_lookup(lookup_type, value)

File "C:\Python25\Lib\site-packages\django\db\models\fields\__init__.py"


in get_db_prep_lookup
202. return [self.get_db_prep_value(value)]

File "C:\Python25\Lib\site-packages\django\db\models\fields\__init__.py"


in get_db_prep_value
353. return int(value)

Exception Type: ValueError at /admin/tvsite/areas/1/areas/batzos.jpeg/
Exception Value: invalid literal for int() with base 10: '1/areas/batzos.jpeg'

2008/9/18 kelvin pompey <silko...@gmail.com>:

Lisa Dusseault

unread,
Sep 18, 2008, 11:50:46 AM9/18/08
to django...@googlegroups.com
I've seen the same problem with FileFields, so it's not just ImageFields.  I haven't figured it out yet.  I can make a link to the file work from the main UI, but I don't know how the admin constructs its link in an unmodified admin form.

Lisa

kelvin pompey

unread,
Sep 18, 2008, 1:35:02 PM9/18/08
to django...@googlegroups.com
Is there a way to modify the html for the admin form to display the image using the html img tag instead of having a link to the image?

barbara shaurette

unread,
Sep 19, 2008, 11:43:34 AM9/19/08
to Django users
Try logging out your SQL and look for any suspicious INSERTs - I've
run across this error a few times, under different circumstances,
always because my code is trying to insert a string when the column is
expecting an integer.

Srik

unread,
Sep 20, 2008, 6:22:36 AM9/20/08
to Django users
Make sure you have MEDIA_URL set :)

Run into similar error, setting MEDIA_URL resolved it :)

kelvin pompey

unread,
Sep 20, 2008, 10:07:26 AM9/20/08
to django...@googlegroups.com
ok I've set the MEDIA_URL and MEDIA_ROOT, but when I click the link I get the 404 file not found error message. If i set ADMIN_MEDIA_PREFIX to a blank string then I can access the link. But there is a problem, when I try to change the image through the form I get a page does not exist error message. 

My current settings are 

MEDIA_ROOT = 'd:sites/sgms/media/'
ADMIN_MEDIA_PREFIX = '/media/'

and the model 

class Student(models.Model):
    photo = models.ImageField(upload_to='photos')

I am using the automatic admin site. 

mrtot

unread,
Oct 1, 2008, 3:48:30 PM10/1/08
to Django users
Hi Kelvin,

I just ran into that problem, too.
However the hint to MEDIA_URL was correct!

You must add the following to the very bottom of your urls.py:

if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': 'd:sites/sgms/media'}),
)

This is described here:
http://docs.djangoproject.com/en/dev/howto/static-files/

Greetz,
M

On 20 Sep., 16:07, "kelvin pompey" <silkodys...@gmail.com> wrote:
> ok I've set the MEDIA_URL and MEDIA_ROOT, but when I click the link I get
> the 404 file not found error message. If i set ADMIN_MEDIA_PREFIX to a blank
> string then I can access the link. But there is a problem, when I try to
> change the image through the form I get a page does not exist error
> message.
> My current settings are
>
> MEDIA_ROOT = 'd:sites/sgms/media/'
> MEDIA_URL = 'http://localhost:8000/media/'
> ADMIN_MEDIA_PREFIX = '/media/'
>
> and the model
>
> class Student(models.Model):
>     photo = models.ImageField(upload_to='photos')
>
> I am using the automatic admin site.
>

Jyothi Naidu

unread,
Apr 17, 2015, 9:18:20 AM4/17/15
to django...@googlegroups.com, silko...@gmail.com

Hi Kelvin,


I am also having the similar issue where i am not able to solve it
invalid literal for int() with base 10: ''
Request Method:POST
Request URL:http://172.19.7.125:8001/super-admin-dashboard/status-change/
Django Version:1.6
Exception Type:ValueError
Exception Value:
invalid literal for int() with base 10: ''
Exception Location:/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 1073
Python Executable:/usr/local/bin/python
Python Version:2.7.3
Python Path:
['/home/kra/jyothi_pms',
 '/usr/local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/python_ntlm-1.0.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/cx_Oracle-5.1.2-py2.7-linux-i686.egg',
 '/usr/local/lib/python2.7/site-packages/RBTools-0.7.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/six-1.9.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/ReviewBoard-2.0.13-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/Whoosh-2.6.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/recaptcha_client-1.0.6-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pytz-2014.10-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/python_memcached-1.53-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/python_dateutil-1.5-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/Pygments-2.0.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/paramiko-1.15.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/mimeparse-0.1.3-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/Markdown-2.4.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/docutils-0.12-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/django_haystack-2.3.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/Djblets-0.8.15-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/django_evolution-0.7.4-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/ecdsa-0.13-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pycrypto-2.6.1-py2.7-linux-i686.egg',
 '/usr/local/lib/python2.7/site-packages/pillowfight-0.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/feedparser-5.1.3-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/django_pipeline-1.3.27-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/futures-2.2.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/mod_wsgi-4.4.8-py2.7-linux-i686.egg',
 '/usr/local/lib/python2.7/site-packages/django_lint-0.0.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pylint-1.4.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/astroid-1.3.4-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/logilab_common-0.63.2-py2.7.egg',
 '/usr/local/lib/python27.zip',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/usr/local/lib/python2.7/lib-old',
 '/usr/local/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/site-packages']







 if 'audit_info_manage' in request.POST:
192         #fullname = Employee.objects.get(emp_id=request.POST['emp_id'])
193         audit_manage_key = request.POST.get('audit_info_getdata')
194         if audit_manage_key:
195             audit_manage_key = request.POST.get('audit_info_getdata')
196             if audit_manage_key:
197                 try:
198                     audit_info = EmployeeAuditInfo.objects.get(pk=audit_manage_key)
199                     SUCCESS_MESSAGE = 'Updated Status successfully'
200                 except EmployeeAuditInfo.DoesNotExist:
201                     audit_info = EmployeeAuditInfo()
202                     SUCCESS_MESSAGE = 'Disable an Employee successfully'
203
204             if audit_info:
205                 #form_emp_id = int(request.POST['emp_id'])
206                 employee = Employee.objects.get(emp_id=request.POST['emp_id'])
207                 employee.save
208                 audit_info = EmployeeAuditInfo()
209                 audit_info.emp_id = employee
210                 audit_info.status = request.POST['status']
211                 audit_info.updated_by = request.user
212                 audit_info.created_on = request.POST['created_on']
213                 audit_info.modified_on = request.POST['modified_on']
214                 audit_info.reason = request.POST['reason']
215                 audit_info.save()



Stephen J. Butler

unread,
Apr 17, 2015, 10:27:01 AM4/17/15
to django...@googlegroups.com, silko...@gmail.com
Line 207 doesn't save the employee object. You forgot ().
Reply all
Reply to author
Forward
0 new messages