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 9321849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:56:39+00:00 2026-06-19T03:56:39+00:00

I have a python script that’s running periodically on Heroku using their Scheduler add-on.

  • 0

I have a python script that’s running periodically on Heroku using their Scheduler add-on. It prints some debug info, but when there’s a non-ASCII character in the text, I get an error in the logs like:

SyntaxError: Non-ASCII character '\xc2' in file send-tweet.py on line 40, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

That’s when I have a line like this in the script:

print u"Unicode test: £ ’ …"

I’m not sure what to do about this. If I have this in the script:

import locale
print u"Encoding: %s" % locale.getdefaultlocale()[1]

then this is output in the logs:

Encoding: UTF-8

So, why is it trying, and failing, to output other text in ASCII?

UPDATE: FWIW, here’s the actual script I’m using. The debugging output’s in line 38-39.

  • 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-06-19T03:56:41+00:00Added an answer on June 19, 2026 at 3:56 am

    As the error says:

    no encoding declared
    

    i.e there is no encoding declared in your Python source file.

    The linked PEP tells you how to declare an encoding in your Python source: the encoding should be set to the table that your editor/IDE uses when you input the unicode character £ from your example. Most likely UTF-8 is assumed, so at the first line of your send-tweet.py put this:

    # coding=utf-8
    

    If the first line already contains a path directive like:

    #!/usr/local/bin/python
    

    then put the encoding directive on the second line, e.g.

    #!/usr/local/bin/python
    # coding=utf-8
    

    Also, when writing Unicode characters in your Python source and declaring UTF-8 encoding, you must use an editor with UTF-8 file saving support, i.e. an editor that can serialize Unicode code points to UTF-8.

    In this regard, please note that Unicode and UTF-8 are not the same. Unicode refers to the standard, while UTF-8 is a specific encoding that determines how to serialize Unicode code points into a string that is compatible with ASCII and which uses 1 to 4 bytes to represent the original Unicode string.

    So in the Python interpreter a string might be stored as Unicode, but if you want to write a Unicode string as UTF-8 you need to explicitly serialize the string to UTF-8 first, e.g.

    s.encode("utf-8")
    

    This is important especially when outputting Unicode strings to byte-sized streams, e.g. when writing to a log file handle which typically assumes byte-sized characters, i.e. UTF-8 for content that contains non-ASCII characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script that is using some closed-box Python functions (i.e. I
I have a Python script that is running a few ls commands. This script
I have a python script that makes a series of url calls using urllib2.
I have a python script that executes linux commands with timeout using a while
I have a python script that runs a subprocess to get some data and
I have a python script that needs to do some communication with a C#
I have a python script that I'd like to add to cron. The script
I have a Python script that processes some data and then inserts it into
I have a python script that is using the SIGSTOP and .SIGCONT commands with
I have a Python script that is running on a Linux server that has

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.