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

  • Home
  • SEARCH
  • 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 5991439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:23:11+00:00 2026-05-22T23:23:11+00:00

I am trying to query a MySQL database using webpy. From the SQL query,

  • 0

I am trying to query a MySQL database using webpy. From the SQL query, I get the following.

<Storage {'title': u'Learn web.py', 'done': 0, 'id': 0L, 'mytime': datetime.datetime(2011, 5, 30, 10, 53, 9)}>

I tried to serialize the data using json.dumps(data) into JSON format, however I get an error indicating that the data is not serializable.

I could probably iterate through each key value pair and put it into another dictionary however that seems like too much work.

Any suggestions on best approaches?

Edit:
I think my problem is because I have datetime.datetime(2011, 5, 30, 10, 53, 9) in the data. I removed the mytime column from the database and everything worked. Is there a way to include the mytime column into the JSON string?

  • 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-22T23:23:11+00:00Added an answer on May 22, 2026 at 11:23 pm

    You can extend json.JSONEncoder to handle dates:

    I’ve not tested this using the Storage object as an argument, but as you say it works when there’s no date in the query, I think this should work. (See the json module docs for information about extending the encoder object).

    import datetime, json
    
    class ExtendedEncoder(json.JSONEncoder):
    
        def default(self, o):
            if isinstance(o, datetime.datetime):             
                # If it's a date, convert to a string
                # Replace this with whatever your preferred date format is
                return o.strftime("%Y-%m-%d %H:%M:%S")  
    
            # Defer to the superclass method
            return json.JSONEncoder(self, o)
    

    Then, if “result” is your storage object

    json_string = json.dumps(result, cls=ExtendedEncoder)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to query a MySQL database using an array but I'm having trouble!
I'm trying to fetch from a MySQL Database using PHP and at the moment
I'm trying to create a simple database table using the PHP MySQL query Create
I am trying to implement a web search functionality on a MySQL database using
I am using php query to retrieve information from a mysql database with mysql_fetch_array
I am trying to display from a MySQL Database using PHP and Ajax but
I'm trying to search two fields as one from a MySQL database using PHP.
I am trying to get the user details form mysql database by using the
I'm trying to insert text into a MySQL DataBase from a form using PHP.
I am trying to write a MySQL query that retrieves one record from table

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.