Reputation: 99
I want to print the last response from my GET request using Grinder
, here is my code:
response_string = httpUtilities.getLastResponse().getText()
print str(response_string)
I got exception:
'ascii' codec can't encode character u'\ufffd' in position
1: ordinal not in range(128) at this line :
print str(response_string)
My question is how to convert java.lang.String
.
I got from httpUtilities.getLastResponse().getText()
into python string?
Response has
charset='utf-8'
Upvotes: 1
Views: 384
Reputation: 40
I had got the exact same error.. Here's a tweak for this kind of response..
try:
safe_str = response_string.encode('ascii', 'ignore')
print("text: "+safe_str)
This will definitely work. :)
Upvotes: 1
Reputation: 13869
No conversion should be required. Change
print str(response_string)
to
print response_string
Upvotes: 1