Trouple with elinux guide - RPi Email IP On Boot Debian


5 posts
by rincewind2002 » Mon Jul 23, 2012 6:19 pm
I'm having problems getting this python script working on my Wheezy Debian RPi.

http://elinux.org/RPi_Email_IP_On_Boot_Debian

I keep getting the following error message

Code: Select all
SyntaxError: Non-ASCII character '\xc2' in file /home/******/code/ip_mailer.py on line 22, but no encoding declared;


I've copy & pasted the code exaclty as it is on that page, but I keep getting error messages when I try to execute the script - FYI I've not done all the messing about with boot.rc yet. I just wanted to make sure the script works before I do that.

I'm entirely new to Python, but I figured I couldn't go wrong with a copy & paste from a site like this one - obviously I was wrong LOL. Any ideas what the problem is?

The line in question appears to be -
Code: Select all
my_ip = 'Your ip is %s' %  ipaddr

I've tried removing the % ipaddr form the end of this line & that clears up the problem, but then I get the same error code on line 24. Removing the similar part of line 24 after the second % also gets rid of that error. But then I'm left with a useless script that doesn't pass any useful info to an email :lol:
Posts: 3
Joined: Mon Jul 23, 2012 5:55 pm
by KCarscadden » Mon Jul 23, 2012 7:29 pm
Somehow an strange character has appeared in your file. Edit the file and put back the stuff you erased, but verify that there are no non-printing characters in the lines where you get the errors by deleting then re-entering the space characters and verify there is nothing after the last printing character by deleting until the next line joins with the current line, then re-enter the new-line character.

Then try running the program again.
Posts: 49
Joined: Sat Jun 09, 2012 9:00 pm
Location: Canada
by rincewind2002 » Mon Jul 23, 2012 7:52 pm
Well that's awesome! Worked like a charm - though I don't know how the erroneous characters appear in the first place :?

Thankyou for a speedy & helpful reply! :)
Posts: 3
Joined: Mon Jul 23, 2012 5:55 pm
by timhoffman » Tue Jul 24, 2012 12:19 am
cutting and pasting code from web pages can often bring with it unicode or UTF-8 (non-ascii) characters.
You get similiar problems from word.
Posts: 85
Joined: Sat Nov 05, 2011 11:31 pm
by rincewind2002 » Wed Jul 25, 2012 6:32 pm
Is there a safe way to copy code from a webpage then, without producing these non-ASCII characters?

I mean other than typing it all out myself, obviously! ;)
Posts: 3
Joined: Mon Jul 23, 2012 5:55 pm