Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6212925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:36:10+00:00 2026-05-24T06:36:10+00:00

the error sounds very straight forward but am unable to fix it. I tried

  • 0

the error sounds very straight forward but am unable to fix it. I tried changing in my dictionary but am not going anywhere and I thought maybe someone in here can help me point out what I need to do to solve it. Below is my code

blog_calendar = BlogI18n.objects.filter(language=request.LANGUAGE_CODE,
                                        blog__published_at__gte=datetime(year, month, 1),
                                        blog__published_at__lte=datetime(year, month, calendar.monthrange(year, month)[1])
                                        ).order_by('-blog__published_at').select_related()

try:
    calendar_response = {}
    calendar_response['properties'] = []
    calendar_response['properties'].append({'next_url' : reverse('blog-archives-month-year',
                                                                 args=[(date(year, month, 1)-timedelta(days=31)).year, (date(year, month, 1)-timedelta(days=31)).month])}
    )
    calendar_response['properties'].append({'prev_url' : reverse('blog-archives-month-year',
                                                                 args=[(date(year, month, 1)+timedelta(days=31)).year, (date(year, month, 1)+timedelta(days=31)).month])}
    )
    calendar_response['current_month'] = []
    calendar_response['current_month'].append({'month':'%s, %s' % (calendar.month_name[month], year)})
    calendar_response['events'] = []
    if blog_calendar:
        calendar_response['events'].append(dict((i.blog.published_at.date(), (i.blog.slug, i.title)) for i in blog_calendar))
    else:
        calendar_response['events'].append(None)
except Exception, e:
    print e.__str__()


if  request.is_ajax():
    # try converting the dictionary to json
    try:
        from django.core.serializers.json import DjangoJSONEncoder
        return HttpResponse(simplejson.dumps(calendar_response, cls=DjangoJSONEncoder), 
                            mimetype="application/json")
    except Exception, e:
        return HttpResponse(e.__str__())

when converting its returning TypeError unable to convert to json (keys must be a string) when I comment out the following line

    calendar_response['events'].append(dict((i.blog.published_at.date(), (i.blog.slug, i.title)) for i in blog_calendar))

it works, so the problem is in this, any idea how i can rebuild my dictionary in a way that the simplejson would understand it?

regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:36:11+00:00Added an answer on May 24, 2026 at 6:36 am

    You have to convert all your keys to strings.

    In this line:

    calendar_response['events'].append(dict((i.blog.published_at.date(), (i.blog.slug, i.title)) for i in blog_calendar))
    

    The culprit is the i.blog.published_at.date() expression. Substitute it with something which returns a string, as for example:

    str(i.blog.published_at.date())
    

    or:

    i.blog.published_at.date().isoformat()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question sounds outrageous, but VS is giving me an error when I check
The subject sounds unclear, but the logic is very simple. I have a returned
I have an idea that sounds like it might work but I'm not entirely
I'm sure this is going to sound very weird, but I'll ask anyway. I
I'm very new to the world of C++ error handling, but I was told
I am a .NET Developer, but the question I am having is not related
I know this sounds like a broad question but I can narrow it down
This may sound very stupid question , but I can't find any documentation that
I wrote this simple query statement: INSERT INTO merchants ('firstName','lastName') VALUES ('Bob','Smith') Sounds very
I got a very strange error on my android apk that only appears if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.