7
I am trying to build a R function to download multiple documents directly from the system provided by CVM.
The general instructions given by the CVM for the multiple download are described in: http://sistemas.cvm.gov.br/Port/DownloadArqs/download02.htm
In summary, access to the system depends on login and password authentication and requires informing the query parameters via the POST method. The system will respond in XML, providing the Urls to download the documents.
What I want to do is return in R the list containing these Urls. For this, I tried to write a simple function using the package "httr", described below:
sist_cvm <- "https://www.rad.cvm.gov.br/DOWNLOAD/SolicitaDownload.asp"
login <- list(txtLogin = "MEU_LOGIN", txtSenha = "MINHA_SENHA", txtData = "15/04/2015", txtHora = "00:00", txtDocumento = "4")
library(httr)
acesso <- POST(url=sist_cvm, body=login, encode="multipart", verbose())
However, when trying to run, returns the following error:
SSL Certificate problem: Error in Function (type, msg, asError = TRUE)
Note: I tried to make multiple combinations when writing the function POST
, varying encode
as form
, multipart
and json
, and including or omitting verbose()
. I also tried to replace the login and password elements in the list login
for authenticate("MEU_LOGIN", "MINHA_SENHA")
. In all cases, the same error was returned.
Could someone give me some suggestions, please?
Thank you!
Can’t test without user/password, but I found two answers (1, 2) on Soen that might help you. Basically, you need to indicate a valid certificate for the connection to the server to be successful.
– Molx
Dear Molx, I haven’t been able to yet... the most I got when I added "verifypeer = FALSE" was to return the same result I got when I tried to access the CVM multiple download system without entering login and password (message "incorrect login".
– tpiccarelli
But I have WAMP installed on my PC and can do multiple downloads only in the conventional way (manual filling) with the HTML code: <body> <form method="post" action="https://WW.RAD.CVM.GOV.BR/DOWNLOAD/SolicitaDownload.asp"> <p>Login: <input="text type name" ="txtLogin" value="MEU_LOGIN"> <p>Password: <input type="text" name="txtSenha" value="MINHA_SENHA"> <p>Date: <input type="text" name="txtData" value="13/03/2015"> <p>Time: <input type="text" name="txtHora" ="00:00 value"> <p>Document: <select name="txtDocument"> <option value="DFP" Selected="Selected">DFP </select></p>
– tpiccarelli
Try changing the NCO to "form" instead of "Multipart", it is another thing to check if you are passing the certificate, as the link of the Molx post. cafile <- system.file("Curlssl", "cacert.pem", package = "Rcurl") access <- POST(url=sist_cvm, body=login, Encode="form", verbose(), config(cainfo = cafile))
– Icaro Bombonato
Molx and Icarus, thank you for trying to help you. But you didn’t. I will think of another alternative for automating the download of the files. Access via R crashes even on authentication, unfortunately.
– tpiccarelli