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 8538839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:13:03+00:00 2026-06-11T11:13:03+00:00

The problem: I’m about to parse a log file in Python 2.6. Problems arose

  • 0

The problem:

I’m about to parse a log file in Python 2.6. Problems arose parsing the common log date string into a time object:

13/Sep/2012:06:27:18 +0200

What I tried already

Use dateutils.parser.parse

I already tried using dateutils.parser.parse but it failed parsing it with the following error:

ValueError: unknown string format

Use time.strptime

I tried time.strptime with the format string %d/%b/%Y:%H:%M:%S %z but ran into trouble when parsing the timezone:

ValueError: 'z' is a bad directive in format '%d/%b/%Y:%H:%M:%S %z'

Does anyone know, where the error is? Or is it just the wrong approach?

Final solution

Finally I decided to use time.strptime with stripping off the timezone information:

time.strptime(datestring[:-6], '%d/%b/%Y:%H:%M:%S')

The reason don’t want to use dateutils is that dateutils is way slower than strptime (which actually calls a C function).

  • 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-06-11T11:13:05+00:00Added an answer on June 11, 2026 at 11:13 am

    This is what I see:

    • dateutil dislikes having the time appended to the date
    • the %z directive is not supported by your underlying C implementation (see this question)

    A quick and easy solution (though, not really elegant):

    >>> s = '13/Sep/2012:06:27:18 +0200'
    >>> dateutil.parser.parse(s.replace(':', ' ', 1))
    datetime.datetime(2012, 9, 13, 6, 27, 18, tzinfo=tzoffset(None, 7200))
    

    As a reminder, optional third parameter to replace is the max replacement count.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem! I Have the following input (rules) from a flat file (talking about numeric
Problem: I'm streaming my video from a php file with stream_get_contents(); using Flowplayer as
Problem One: </a> 19-10-2011, 04:49 PM </td> <td class=thread How to fetch the DATE
Problem: I wrote a hello world java program, compiled and created a jar file
Problem I have a xib file with a UIImageView over the top of the
I have a French site that I want to parse, but am running into
PROBLEM : I am having problems getting socket.IO to connect in some circumstances, so
Problem: Every time I start a new session of Internet Explorer, the web application
Problem: If user is not logged into GameCenter account - GameCenter authentication view is
I am currently running into a problem where an element is coming back from

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.