httr icon indicating copy to clipboard operation
httr copied to clipboard

Error with non-unicode character in response from POST

Open glaroc opened this issue 4 years ago • 1 comments

I run httr::POST with the following to an API endpoint as JSON

{
    "vascan_id": 5484,
    "name": "Equisetum ×nelsonii",
    "vernacular_fr": "prêle de nelson",
    "vernacular_en": "nelson's scouring-rush",
    "rank": "espèce_hybride",
    "category": "plantes",
}

Note the "×" in the name value. This gets accepted properly to the API and inserted into our database. However, httr errors out on the response with

Error in substring(u, so, so + ml - 1L) : invalid multibyte string, element 1

It seems that it can deal with the non-unicode character for posting to the API, but not in the response. Note that the response is encoded in utf-8. Doing the same POST with Postman poses no issues. Are there any ways to prevent this error ?

glaroc avatar Jun 22 '21 19:06 glaroc

I am getting the same response when using httr. When I use curl::curl_fetch_memory, it works:

url <- "https://ww2.stj.jus.br/websecstj/cgi/revista/REJ.cgi/ITA?seq=1975824&tipo=0&nreg=202001655224&SeqCgrmaSessao=&CodOrgaoJgdr=&dt=20200904&formato=PDF&salvar=false"
response <- httr::GET(url)
response <- curl::curl_fetch_memory(url)

jjesusfilho avatar Nov 18 '21 12:11 jjesusfilho

httr has been superseded in favour of httr2, so is no longer under active development. If this problem is still important to you in httr2, I'd suggest filing an issue offer there 😄. Thanks for using httr!

hadley avatar Oct 31 '23 18:10 hadley