Skip to content

open a zip file

2 messages · Glenn Schultz, Roy Mendelssohn - NOAA Federal

#
All I have this code

 #=============== Function Downloads the Factor File
  #' A function to download FNMA Pool Factors
  #' 
  #' @importFrom httr GET
  #' @importFrom httr write_disk
  #' @importFrom httr http_status
  #' @importFrom httr progress
  #' @export
  FNMAPoolFactor <- function(){
    Year <- format(Sys.Date(), "%Y")
    Month <- format(Sys.Date(), "%m")
    response <- 
      httr::GET(
        paste("https://mbsdisclosure.fanniemae.com/disclosure-docs/monthly/",
            "mbs", 
            as.character(Month), 
            as.character(Year),
            ".zip", 
            sep = ""),
      httr::write_disk(paste("~/FNMA/mbs/",
                       as.character(Month), 
                       as.character(Year),
                       ".zip", 
                       sep = ""), overwrite = FALSE), httr::progress())
  httr::http_status(response)
  }

Which results in a zip file but I cannot open the file with unzip or any other R functions what have I done wrong?

Glenn
#
If I break it into parts, I find that the "GET" fails.
+            "mbs", 
+            as.character(Month), 
+            as.character(Year),
+            ".zip", 
+            sep = "")
[1] "https://mbsdisclosure.fanniemae.com/disclosure-docs/monthly/mbs082016.zip"
Response [https://mbsdisclosure.fanniemae.com/disclosure-docs/monthly/mbs082016.zip]
  Date: 2016-08-08 02:02
  Status: 404
  Content-Type: text/html; charset=iso-8859-1
  Size: 235 B
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /disclosure-docs/monthly/mbs082016.zip was not found on this server.</p>
</body></html>


Your saved file will have the ending ".zip" no matter what, because that is what you called it, but I wouldn't be surprised if it just a txt file with the error message.

HTH,

-Roy
+            "mbs", 
+            as.character(Month), 
+            as.character(Year),
+            ".zip", 
+            sep = "")
[1] "https://mbsdisclosure.fanniemae.com/disclosure-docs/monthly/mbs082016.zip"
Response [https://mbsdisclosure.fanniemae.com/disclosure-docs/monthly/mbs082016.zip]
  Date: 2016-08-08 02:02
  Status: 404
  Content-Type: text/html; charset=iso-8859-1
  Size: 235 B
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /disclosure-docs/monthly/mbs082016.zip was not found on this server.</p>
</body></html>

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.