1

を使用して GET リクエストからの最後の応答を出力したいのですGrinderが、コードは次のとおりです。

response_string = httpUtilities.getLastResponse().getText()
print str(response_string)

私は例外を得ました:

 'ascii' codec can't encode character u'\ufffd' in position 
  1: ordinal not in range(128) at this line : 

    print str(response_string)

私の質問は、変換する方法java.lang.Stringです。

私はhttpUtilities.getLastResponse().getText()python文字列から取得しましたか?レスポンスは charset='utf-8'

4

2 に答える 2

1

まったく同じエラーが発生しました..これは、この種の応答の微調整です..

try:
   safe_str = response_string.encode('ascii', 'ignore')
   print("text: "+safe_str)

これは間違いなく機能します。:)

于 2013-10-23T11:53:48.577 に答える