1

I've been using httr to export data from REDCap databases into R for a few months now. We recently upgraded our R Studio Server to the most recent version (v0.98.1049) and upgraded to R 3.1.1 at the same time. After that upgrade, my httr::POST calls stopped working, sometimes. The error I keep getting is

Error in function (type, msg, asError = TRUE)  : 
GnuTLS recv error (-9): A TLS packet with unexpected length was received.

At first I thought it might be an SSL issue, but the error only occurs in certain databases, and in those databases, I can still download the data using RCurl. That is, this code will work

RCurl::postForm(uri=[URL],
                .params=list(token=[TOKEN],
                             content='record',
                             format='csv'))

But this code will not

httr::POST(url=[URL],
           body=list(token=[TOKEN],
                     content='record',
                     format='csv'))

Adding further to my confusion, even though I can't export data in projects where this error occurs, I can import data.

I'm out of ideas on where to start. I'd much appreciate any ideas on what might be going wrong here.

(I'd like to provide a reproducible example, but I'm afraid I'm working with healthcare data. sorry)

As requested, here's the verbose() output. It's a slightly different call, but produces the same error. (I used a call that wouldn't risk exposing confidential information)

  > httr::POST(url=whi$url,  
  +            body=list(token=whi$token,  
  +                      content='metadata',  
  +                      format='csv'),   
  +            httr::verbose(data_in=TRUE, info=TRUE))  
  *  Hostname was found in DNS cache  
  *  Hostname in DNS cache was stale, zapped  
  *      Trying 172.26.30.4...  
  *  Connected to [URL] (172.26.30.4) port 443 (#7)  
  *  found 153 certificates in /home/nutterb/R/x86_64-unknown-linux-gnu-library/3.1/httr/cacert.pem  
  *  SSL re-using session ID  
  *      server certificate verification OK  
  *      common name: [URL] (matched)  
  *      server certificate expiration date OK  
  *      server certificate activation date OK  
  *      certificate public key: RSA  
  *      certificate version: #3  
  *      subject: OU=Domain Control Validated,CN=[URL]  
  *      start date: Thu, 10 Apr 2014 17:06:17 GMT  
  *    
  *      expire date: Sat, 21 Mar 2015 16:35:07 GMT  
  *    
  *      issuer: C=US,ST=Arizona,L=Scottsdale,O=Starfield Technologies\, Inc.,OU=http://certs.starfieldtech.com/repository/,CN=Starfield Secure Certificate Authority - G2  
  *      compression: NULL  
  *      cipher: AES-128-CBC  
  *      MAC: SHA1  
  -> POST /redcap/api/ HTTP/1.1  
  -> User-Agent: curl/7.35.0 Rcurl/1.95.4.1 httr/0.5.0.9000  
  -> Host: [URL]  
  -> Accept-Encoding: gzip  
  -> accept: application/json, text/xml, */*  
  -> Content-Length: 374  
  -> Expect: 100-continue  
  -> Content-Type: multipart/form-data; boundary=------------------------05c968969cc362a9  
  ->   
  <- HTTP/1.1 100 Continue  
  >> --------------------------05c968969cc362a9  
  >> Content-Disposition: form-data; name="token"  
  >>   
  >> [TOKEN]  
  >> --------------------------05c968969cc362a9  
  >> Content-Disposition: form-data; name="content"  
  >>   
  >> metadata  
  >> --------------------------05c968969cc362a9  
  >> Content-Disposition: form-data; name="format"  
  >>   
  >> csv  
  >> --------------------------05c968969cc362a9--  
  <- HTTP/1.1 200 OK  
  <- Date: Sat, 06 Sep 2014 09:55:43 GMT  
  <- Expires: 0  
  <- cache-control: no-store, no-cache, must-revalidate  
  <- Pragma: no-cache  
  <- Access-Control-Allow-Origin: *  
  <- Vary: Accept-Encoding  
  <- Content-Type: text/html; charset=utf-8  
  <- Connection: close  
  <- Content-Encoding: gzip  
  <-   
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  <<  NA  
  *  GnuTLS recv error (-9): A TLS packet with unexpected length was received.  
  *  Closing connection 7  
  Error in function (type, msg, asError = TRUE)  :   
    GnuTLS recv error (-9): A TLS packet with unexpected length was received.  
  In addition: There were 11 warnings (use warnings() to see them)  
  > warnings()  
  Warning messages:  
  1: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  2: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  3: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  4: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  5: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  6: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  7: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  8: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  9: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  10: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  11: In strsplit(x, "\n", fixed = TRUE) : input string 1 is invalid in this locale  
  > 
wibeasley
  • 5,000
  • 3
  • 34
  • 62
Benjamin
  • 16,897
  • 6
  • 45
  • 65
  • Can you just make up some fake data? Is it even possible for us to easily set up a test REDCap database (i've never used that before)? And it's always the same error "A TLS packet with unexpected length was received"? What `httr` version are you using? And what OS? (did that change during the upgrade?) – MrFlick Sep 04 '14 at 17:05
  • I could deidentify a dataset and provide a data dictionary, but you would still need a REDCap instance to test this on. I'm getting the error on a Linux server (2.6.32-55). `httr` version 0.5.0.9000. The OS didn't change in the upgrade, but I tried running my code on a Windows 7 machine and it worked, so that seems to narrow it down to a system property. I just can't think of what. – Benjamin Sep 05 '14 at 13:37
  • Could you try using verbose()? Unfortunately it's going to be impossible to diagnose with out a reproducible example. – hadley Sep 06 '14 at 01:08
  • @hadley, I've been digging around with this a lot more today. I eventually found a point in the file that I was trying to download that resulted in the error. Long story short, as long as file has no more than 8,000 characters, I can download the file. As soon as I hit 8,001 characters, I get the error. To make matters worse, though, when I try to run the same code on the development server, it works fine all the way up to 200,000 characters (and presumably beyond). That kind of kills my idea about there being a certain character in the way. – Benjamin Sep 12 '14 at 15:14
  • Can you share more details over email? Also try `options(warn = 2)` plus traceback to find out where those warnings are coming from. – hadley Sep 13 '14 at 00:27

0 Answers0