SyntaxError: non-ASCII character '\ xe2'

I wrote a program to give me Mega Doge Coin value

import time
import urllib2
from datetime import datetime

def get_HTML():
    response = urllib.request.urlopen('http://www.dogepay.com')
    html = response.read()
    return html

def get_Value(rawHTML):
    index = rawHTML.find("CCFF00")
    while(rawHTML[index] != "$"):
            index = index + 1
    index = index + 1
    value = ""
    while(rawHTML[index].isdigit() or rawHTML[index] == ‘.’):
            value = value + rawHML[index]
            index = index + 1
    return float(value)

def get_DateTime():
    now = datetime.now()
    return '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, 
                                  now.minute, now.second)

def print_Output(DogeCoinValue, TimeDate):
    print timeDate + " $" + str(dogeCoinValue)

while(True):
    rawHTML = get_HTML()
    dogeCoinValue = get_Value(rawHTML)
    timeDate = get_DateTime()
    print_Output(dogeCoinValue, timeDate)
    time.sleep(5)

      

But when I go to run I get

File "MegaDogeCoinTicker.py", line 11
SyntaxError: Non-ASCII character '\xe2' in file MegaDogeCoinTicker.py on line 
11, but no encoding declared; see http://www.python.org/peps/pep-0263.html 
for details

      

What do I need to do to fix this? It worked when I ran it on my pi, but I can't get it to work on my laptop. My laptop is running Python 2.7.5

+3


source to share


2 answers


In addition to not using non-ascii quotes, you must add at the top line of your code:

# -*- coding: utf-8 -*-

      



more details

+10


source


You should use standard ASCII quotes:

index = rawHTML.find("CCFF00")

      



but not:

index = rawHTML.find("CCFF00")

      



+8


source







All Articles