Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:36+00:00 2026-05-25T11:37:36+00:00

I am getting this error: File run.py, line 37, in <module> print str1 UnicodeEncodeError:

  • 0

I am getting this error:

File "run.py", line 37, in <module>
 print str1
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 24-29: ordinal not in range(256)

When trying to simply print some Japanese text. Actually it seems the string looks like this:

\u5149\u66dc\u65e5\u3067\u30e9\u30c6 \u30d4\u30af\u30b7\u30fc\u4e71\u7372\u884c\u304d\u307e\u3059 \u5e0c\u671b\u8005\u52df\u96c6\u4e2d\u3067\u3059\uff3e\uff3e

Which comes in from a JSON file. How can I print this?

Code:

url = "http://www.blah.com/json"
try:
  result = simplejson.load(urllib2.urlopen(url))
except IOError:
  print "Cannot open URL"
  data = "error"

for msg in result["msg"]:
  str1 = msg["character"] + " : " + msg["message"]
  print str1

repr(str1) is

u'Anys : \u5149\u66dc\u65e5\u3067\u30e9\u30c6 \u30d4\u30af\u30b7\u30fc\u4e71\u7372\u884c\u304d\u307e\u3059 \u5e0c\u671b\u8005\u52df\u96c6\u4e2d\u3067\u3059\uff3e\uff3e'

print(sys.stdout.encoding) is

ISO-8859-1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:37:37+00:00Added an answer on May 25, 2026 at 11:37 am

    The error that you see is because you terminal use latin-1 as encoding, as a side note you can check the encoding of your terminal (assuming that it’s your stdout) by doing in your shell:

    $ python -c "import sys; print sys.stdout.encoding"
    

    And now for printing in UTF-8 you should encode your string to utf-8 manually like this:

    s = u"\u5149\u66dc\u65e5\u3067\u30e9\u30c6 \u30d4\u30af\u30b7\u30fc\u4e71\u7372\u884c\u304d\u307e\u3059 \u5e0c\u671b\u8005\u52df\u96c6\u4e2d\u3067\u3059\uff3e\uff3e"
    print s.encode('utf-8')
    #Output: 光曜日でラテ ピクシー乱獲行きます 希望者募集中です^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this error Traceback (most recent call last): File /home/<username>/flup/server/fcgi_base.py, line 558, in
I am getting this error after adding the libxml2.2.dylib file Linking /Users/Biranchi/Desktop/Funmovies TabBarController/build/Debug-iphonesimulator/funmovies.app/funmovies (1
I keep getting this error, although the file still gets moved into the correct
I am getting this error when i am trying to upload a file of
I'm Getting this error in my development log while uploadify is uploading the file
I am using this php code: exec(unrar e file.rar,$ret,$code); and getting an error code
I can't figure out why I'm getting this error. Please help. Traceback (most recent
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Anyone getting this error when using the new free chart controls MS bought from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.