Closed guslav closed 7 years ago
This is the script I tried using Stack:
#!/usr/bin/env stack
{- stack
--resolver lts-8.9
--install-ghc
runghc
--package download
-}
import Network.Download
tester :: IO Bool
tester = do
let uri = "http://www.google.com"
let path = "/tmp/site.htm"
tag <- openURIString uri
case tag of
Left error -> do
putStrLn $ "Error on downloading: " ++ uri
putStrLn $ "Error message:\n"++ error
return False
Right code -> do
putStrLn $ "Download successful: " ++ uri
writeFile path code
return True
main :: IO ()
main = do
x <- tester
print x
And this is the output I get:
Download successful: http://www.google.com
True
So, it works for me. Can you give ma a reproducible example ? If possible, can you possible try executing my Stack script pasted above and let me know. Note that download
package doesn't support HTTPS
protocol.
Well, it was my fault. 1.) The link I used had an underlying https connection. I didnt notice that. 2.) I tried to use google.com (valid URL) after that, which results in the same error (Im testing inside of ghci). But it is not possible to get a new socket after a failure. I had to restart ghci. Using only :r isn't working.
Code:
import Network.Download
uri1 = "https://www.google.com"
uri2 = "http://www.google.com"
uri3 = "https://www.bing.com"
uri4 = "http://www.bing.com"
tester :: String -> IO Bool
tester uri = do
let path = "/tmp/file.htm"
tag <- openURIString uri
case tag of
Left error -> do
-- putStrLn $ "Error on downloading: " ++ uri
putStrLn $ "Error message:\n"++ error
return False
Right code -> do
-- putStrLn $ "Download successful: " ++ uri
writeFile path code
return True
Results
ghci> tester url2
True
ghci> tester url4
True
ghci> tester url1
False (first invalid URL)
ghci> tester url2
False (URL is valid, but we already had an error before)
ghci> :r
ghci> tester url2
False (URL is valid, but we already had an error before and :r does not reset that, since it is in the c-lib)
Thank you for your time.
Ah thanks. I will close the issue then. I plan to add support for HTTPS
soon once I get some time.
Hallo,
I get the error message "Failed to connect: Resource temporarily unavailable" on every download URL I try. What does that mean and how can I deal with it?
Here is my code:
result: