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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:16:46+00:00 2026-06-09T03:16:46+00:00

As many hopefully can relate, this encoding problem is driving me mental . I

  • 0

As many hopefully can relate, this encoding problem is driving me mental. I would really appreciate some light on this!

End goal is to be able to run the same script.py from both terminal and cron, and from cron with > stdout.txt. And needless to say, I’m having serious encoding troubles.

My script.py runs fine from terminal thus: python script.py

It throws an error, however, when run from terminal thus: python script.py > stdout.txt

It throws same error when run in cron, either way.

I have a python script, entered in crontab -e as root.

This is my script.py header:

#!/usr/bin/python
# -*- coding: utf-8 -*-

This is my cron entry:

* * * * * python /home/ubuntu/parrot/script.py > /home/ubuntu/parrot/stdout.txt

This is my stdout.txt (the relevant part):

Unexpected error!  (<type 'exceptions.UnicodeDecodeError'>, UnicodeDecodeError('ascii', 'blabla some weird text n\xc3\xa5r end', 54, 55, 'ordinal not in range(128)')) 

This is my env from terminal (the relevant part):

LANG=en_US.UTF-8

This is my env from cron (the relevant part):

LANG=en_US.UTF-8

This is the (first) line in script.py throwing the error:

print 'Posting @%s: %s' % (statusObj.user.screen_name.encode('ascii', 'replace'), statusObj.text.encode('utf-8', 'replace'))

Edit:
sys.getdefaultencoding() returns ascii

Any help is greatly appreciated!

  • 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-09T03:16:48+00:00Added an answer on June 9, 2026 at 3:16 am

    If you have control over the statusObj you should check the relevant code where data is being parsed into the object and try to get the input as clean as possible.

    You want to make sure your string is decoded to unicode before you try to encode it.

    If not you can try:

    # try to get the string into unicode
    screen_name = unicode(statusObj.user.screen_name) 
    post = unicode(statusObj.text) # probably an error here?
    output_str = u"Posting @{name}: {post}".format(name=screen_name, post=post)
    print output_str.encode("utf8", "replace") # encode the unicode string on 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a problem I regularly bump into - hopefully someone can clarify to
Hey everyone. Hopefully I can explain this correctly. I have some URL's which I
Hopefully someone can help me debug this problem as EXC_BAD_ACCESS is the only error
I have attempted this is many ways but failed consistently, hopefully you can help
Hopefully I can explain this well enough, but please let me know if more
This is hopefully not a repost of the many other error code 191 messages
I'm not entirely sure what is the best approach to this problem, so hopefully
Hopefully someone can see something which I've missed out or something, because this is
Hopefully I can explain this without overcomplicating the issue, so please bear with me.
Hopefully I can articulate my question well enough to get some clear and usable

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.