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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:50:14+00:00 2026-06-01T21:50:14+00:00

I have a piece of Python code that (for better or worse) checks a

  • 0

I have a piece of Python code that (for better or worse) checks a local file against the same file on a web server. If it’s not there, it downloads it, if it does, it checks the os.stat last modified of the downloaded file against the HTTP header of the same file on the server.

Problem is, it seems these two numbers aren’t equal even when they should be. Here’s the code:

from urllib import urlretrieve
from urllib2 import Request, urlopen
from time import strftime, localtime, mktime, strptime
from os import stat, path

destFile = "logo3w.png"
srvFile = "http://www.google.com/images/srpr/logo3w.png"

if path.exists(destFile):
    localLastModified = stat(destFile).st_mtime
    req = Request(srvFile)
    url_handle = urlopen(req)
    headers = url_handle.info()                        
    srvLastModified = headers.getheader("Last-Modified")
    srvLastModified = mktime(strptime(srvLastModified,
      "%a, %d %b %Y %H:%M:%S GMT"))
    print localLastModified, srvLastModified

else:
    urlretrieve(srvFile, destFile)

The return of the print statement (if you run the code twice) is 1334527395.26 1333350817.0.

Seems to me those two should be the same, but they’re wildly different. The date modified of the file downloaded locally is in fact the date it was downloaded to the local machine, not the last modified date on the server.

Essentially all I’m trying to do is keep a local cache of the file (would be a lot of files in the actual application), downloading it if necessary. I’m half aware that web proxies should do this by default, and I’m running a basic WAMP server where these files are stored, but I’m not sure how to apply this to my PyQt application. There are potentially dozens of files that would need to be downloaded and cached, and about half of them will rarely ever change, so I’m trying to determine the fastest way to check and grab these files.

Perhaps this isn’t even the right way to go about it, so I’m all ears if there are (far better/numerous other) ways to do this.

  • 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-01T21:50:15+00:00Added an answer on June 1, 2026 at 9:50 pm

    urllib.urlretrieve just downloads the file; it does not copy the modification date. You must manually do so using os.utime:

    import os
    
    # current code
    else:
        headers = urlretrieve(srvFile, destFile)[1]
        lmStr = headers.getheader("Last-Modified")
        srvLastModified = mktime(strptime(lmStr, "%a, %d %b %Y %H:%M:%S GMT"))
        os.utime(destFile, (srvLastModified, srvLastModified))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a moderately large piece (a few thousand lines) of Python/Numpy/Scipy code that
I have a piece of Python code, that interacts with a PostgreSQL database via
I have another newbie Python question. I have the following piece of code that
I have this piece of code that is working fine in python 2.7. dist
I currently have a Python 2.6 piece of code that runs two loops simultaneously.
Using Python 2.7 Situation: I have some piece of Python code (that the user
I have a piece of source code in our build that is generated by
I have one piece of Cocoa code I wrote that takes in an XML
I am looking for a piece of code Python code that would give me
I have a piece of C++ code that generates the data. I want to

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.