Plumber: Chinese characters are not supported

Created on 17 Aug 2018  ·  5Comments  ·  Source: rstudio/plumber

Is there any way to set the character set so that the plumber can support Chinese characters?
谢谢!

low medium bug

All 5 comments

@shangfr Do you have a small example plumber file? This way I can reproduce / fix the error you're seeing.

Thank you in advance!

@schloerke My plumber file was written in utf8,but the plumb function default encoding is ANSI , it should be better to specify encoding. Such as : plumb("plumber.R", encoding = "UTF-8")

plumber.R

' Echo the parameter that was sent in

' @param msg The message to echo back.

' @param msgCN The Chinese message to echo back.

' @get /echo

function(msg="",msgCN=""){
list(msg = paste0("The message is: ", msg, "---","中文消息是: ",msgCN))
}

$ curl "http://localhost:8000/echo?msg=hello&msgCN=你好"
Now output : {"The message is: hello---涓枃娑堟伅鏄? 浣犲ソ"}
Correct output : {"The message is: hello---中文消息是: 你好"}

Note, this is only reproducible on Windows because the default encoding is not UTF-8. (Moreover, it may require a windows machine using Simplified Chinese. Replacing the Chinese by Latin-1 and it may be reproducible on any Windows machine.)

There're actually two issues here:

  1. The source file should be parsed as UTF-8 by default as it's in shiny.
  2. The function parameter should be marked as UTF-8 for characters.

A hotfix

@shangfr you can use this as a hotfix for now.

#' @get /echo2
function(msg="",msgCN=""){
  Encoding(msgCN) <- "UTF-8" # by marking it explicitly it will work as an adhoc solution
  list(msg = paste0("The message is: ", msg, "---","中文消息是: ",msgCN))
}

@shangfr It should have been fixed via the PR #312 and #314. You can try after the two PRs being merged. 😄

Thank you. I appreciate your help. Thanks. @shrektan

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EDiLD picture EDiLD  ·  4Comments

dmenne picture dmenne  ·  4Comments

daxilshah picture daxilshah  ·  4Comments

colearendt picture colearendt  ·  4Comments

utkarshsaraf19 picture utkarshsaraf19  ·  3Comments