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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:09:08+00:00 2026-06-11T05:09:08+00:00

I am working with a Django app Pyroven and am doing some major re-working

  • 0

I am working with a Django app Pyroven and am doing some major re-working of its functionality. As part of this I’ve begun writing a testing framework for it, as at present it has no unit tests. By way of background it uses the University of Cambridge Raven service for authentication, and offers an authentication backend for Django to leverage this service.

The issue I’m running into is testing the WLS-Response token from Raven. This forms a string of ! separated values, which include a time field in the format:

%Y%m%dT%H%M%SZ

In my testing code, I’ve created this as:

raven_issue = datetime.now().strftime('%Y%m%dT%H%M%SZ')

and then returned that to the testing URL for processing by the view. The issue comes with the validation that this time is not too far in the past for validation of the response. The code which validates this uses:

def parse_time(t):
    """Converts a time of the form '20110729T123456Z' to a number of seconds
    since the epoch.
    @exception ValueError if the time is not a valid Raven time"""
    time_struct = time.strptime(t, "%Y%m%dT%H%M%SZ")
    return calendar.timegm(time_struct)

Now, when it is passed the string above from the datetime.now() constructor, the validation on this parsed value fails:

# Check that the issue time is not in the future or too far in the past:
if self.issue > time.time() + PYROVEN_MAX_CLOCK_SKEW:
    raise InvalidResponseError("The timestamp on the response is in the future")
if self.issue < time.time() - PYROVEN_MAX_CLOCK_SKEW - PYROVEN_TIMEOUT: 
    raise InvalidResponseError("The response has timed out")

This code fails with my test, claiming that the response has timed out. The values for PYROVEN_MAX_CLOCK_SKEW and PYROVEN_TIMEOUT are 2s and 10s respectively.

This begs the question is there some variability in handling of time I don’t understand? If I put a datetime.now() generated value, with a datetime.timedelta of 2 hours in the future, convert it to the string and pass it to the validation, that doesn’t fail despite the timestamp being in the future, when it should. Why is this, as the logical reading of the code suggests it should?

  • 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-11T05:09:10+00:00Added an answer on June 11, 2026 at 5:09 am

    You are getting confused between local time (as returned by datetime.now() and GMT (as parsed by calendar.timegm()):

    >>> t = datetime.now().strftime('%Y%m%dT%H%M%SZ')
    >>> t
    '20120910T232358Z'
    >>> calendar.timegm(time.strptime(t, "%Y%m%dT%H%M%SZ"))
    1347319438
    >>> time.mktime(time.localtime())
    1347312258.0
    >>> time.mktime(time.strptime(t, "%Y%m%dT%H%M%SZ"))
    1347312238.0
    

    Conclusion: use time.mktime instead of calendar.timegm to turn your values to timestamps.

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

Sidebar

Related Questions

Working on the Django tutorial Writing your own Django app, and I'm on Part
I have been working on a django app on my local computer for some
We are working on a web app with the Django framework and we are
I'm working on a simple webservice in django. This is my first web app
I am working on a django- Google app engine project. A user inserts some
I'm working with my Django app. For some reason an element of a list
I am working on a django app. One part would involve uploading files (e.g.
I've started writing some tests for my Django app and I'm unsure how best
I am working on a Django app that performs some class introspection ahead of
I'm working on a localized Django app with a simple forum. Some posts' timestamps

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.