0

I have a program that runs in IDLE on my laptop and also on my Android phone using a python app. When I try to run it on the Raspberry PI I get an error saying that "No module named request". If I remove request from the end of the statement it loads that portion. Then I get to another error at like 9 which says:

    Traceback (most recent call last):
    File "tibia.py", line 9, in <module>
    words=input('Enter the character name you wish to monitor...\n')
    File "<string>", line 1, in <module>
    NameError: name 'NAME' is not defined

My code is below:

import urllib.request
import time
import smtplib




#define and format character name
words=input('Enter the character name you wish to monitor...\n')
words=str.replace(words," ","+")
words=words.title()

#prepare email body
content=('This is an automated email notifying you that '+words+' is    online.')

#x for infinite loop
x=1
#adding anchors to character name
textToSearchFor = '=' + words + '"'




while x==1:
    try:
        site = urllib.request.urlopen('https://secure.tibia.com/community/?subtopic=worlds&world=Amera')
        HTML = site.read().decode("utf-8")


        if textToSearchFor in HTML:
          print(words + ' is online.')
          time.sleep(60)

       #send email
           mail=smtplib.SMTP('smtp.gmail.com',587)
           mail.ehlo()
           mail.starttls()
           mail.login('email','password')
           mail.sendmail('email@gmail.com','email@gmail.com',content)
           mail.close()

        else:
           print(words + ' is not online.')
           time.sleep(60)


    except:
        print('Error fetching character status.')
        time.sleep(60)
Mobalized
  • 11
  • 2
  • It looks like you're using Python 2.x in some places and 3.x in others - that's not a good idea, as it takes a bit of work to write code that runs correctly in both. The dupe covers one of your errors, for the other see the note at the top of https://docs.python.org/2/library/urllib.html – jonrsharpe Feb 04 '16 at 22:35
  • I didn't realize in order to run in python 3 on the raspberry pi you had to type python3 as the command – Mobalized Feb 05 '16 at 23:14

0 Answers0