0

In this code, https://docs.google.com/document/d/1yhlOtEAcI4qCAzRam4hT5H3xgvQAonHG_k7QaJX2vVk/edit?usp=sharing , I get File "weather.py", line 45 SyntaxError: Non-ASCII character '\xe2' in file weather.py on line 45, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I dont know how to fix this problem, I cant even find \xe2 anywhere!

Can you tell me how to fix the syntax error?

import RPi.GPIO as GPIO   
import pywapi    
import string    
import time    


def code():
 channels = [4, 7, 8, 9, 10, 14, 15, 17, 18, 22, 23, 24, 25]

GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
GPIO.setup(channels, GPIO.OUT)

weather_com_result = pywapi.get_weather_from_weather_com('ZIP')
print (weather_com_result) 

temperature = int(weather_com_result['current_conditions']['temperature'])
temp_f = temperature * 9/5 + 32
cc = (weather_com_result['current_conditions']['text'].lower())
humidity = int(weather_com_result['current_conditions']['humidity'])
#---------------------------------------------------------------------------
if humidity >= 80:
   GPIO.output(7, 1)

if humidity <= 79 and humidity >= 60:
   GPIO.output(8, 1)

if humidity <= 59:
   GPIO.output(25, 1)
#---------------------------------------------------------------------------
if temperature >= 90:
   GPIO.output(14, 1)

if temperature <= 89 and temperature >= 80:
   GPIO.output(14, 1)

if temperature <= 79 and temperature >= 70:
   GPIO.output(18, 1)

if temperature <= 69 and temperature >= 40:
   GPIO.output(23, 1)

if temperature <= 39:
   GPIO.output(24, 1)
#-----------------------------------------------------------------------------
if cc == ‘drizzle’ or ‘light drizzle’ or ‘heavy drizzle’:
   GPIO.output(4, 1)

if cc == ‘rain’ or ‘light rain’:
   GPIO.output(4, 1)

if cc == ‘heavy rain’:
   GPIO.output(17, 1)

if cc == ‘light rain mist’ or ‘rain mist’ or ‘heavy rain mist’:
   GPIO.output(4, 1)

if cc == ‘rain shower’ or ‘light rain showers’:
   GPIO.output(4, 1)

if cc == ‘heavy rain shower’:
   GPIO.output(17, 1)
if cc == 
‘light thunderstorm’ or
‘heavy thunderstorm’ or
‘thunderstorm’ or
‘light thunderstorms and rain’ or
‘heavy thunderstorms and rain’ or
‘thunderstorms and rain’ or
‘light thunderstorms and snow’ or
‘heavy thunderstorms and snow’ or
‘thunderstorms and snow’ or
‘light thunderstorms and ice pellets’ or
‘heavy thunderstorms and ice pellets’ or
‘thunderstorms and ice pellets’ or
‘light thunderstorms with hail’ or
‘heavy thunderstorms with hail’ or
‘thunderstorms with hail’ or
‘light thunderstorms with small hail’ or
‘heavy thunderstorms with small hail’ or
‘thunderstorms with small hail’:
GPIO.output(17,10,9, HIGH)

if cc == ‘light freezing drizzle’ or ‘heavy freezing drizzle’ or ‘freezing drizzle’:
   GPIO.output(4, 1)

if cc == ‘light freezing rain’ or ‘heavy freezing rain’ or ‘freezing rain’:
   GPIO.output(17, 1)

if cc == ‘patches of fog’ or ‘shallow fog’ or ‘partial fog’ or ‘light fog’
   GPIO.output(22, 1)

if cc == ‘fog’ or ‘heavy fog’ or ‘heavy fog patches’ or ‘light fog patches’ or ‘fog patches’:
   GPIO.output(10, 1)

if cc == ‘overcast’:
   GPIO.output(10, 1)

if cc == ‘partly cloudy’ or ‘scattered clouds’:
   GPIO.output(22, 1)

if cc == ‘mostly cloudy’:
   GPIO.output(10, 1)   
GPIO.cleanup()   
while True:    
   code()    
   time.sleep(180)   
  • Considering some sections have been colored/made bold, i think its been saved as a rich text format containing the formatting instructions rather than a simple ascii/unicode format. Suggest converting the contents it as plain ascii/unicode format by copying the content into a simple text editor (notepad/kate/gedit etc) rather than a word processor. you might need to get rid of the any strange symbols/unprintable characters that might show up like squares/boxes – Shreyas Murali Oct 18 '16 at 0:52
1

The problem is with the quotes you used:

if you look at the line with the error:

if cc == ‘drizzle’ or ‘light drizzle’ or ‘heavy drizzle’:

You are using a non ascii quote symbol. One indication of this is the difference in syntax highlighting between your line and the corrected line below.

If you change it like so:

if cc == 'drizzle' or 'light drizzle' or 'heavy drizzle':

If you are using a standard US keyboard the single quote is to the left of the Enter key.

Note: the issue is not limited to that one occurance, and you will need to correct them all.

  • Okay I see it now. What was I using before? – Vicenzo DeVito Oct 19 '16 at 0:52
  • No idea. If I had to guess you copy and pastedd the code from somewhere. – Steve Robillard Oct 19 '16 at 0:53
  • Yea most likely, I was stumped for a while but thankfully you helped! – Vicenzo DeVito Oct 19 '16 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.