我有一个在笔记本电脑上使用IDLE运行的程序,以及使用python应用程序在我的Android手机上运行的程序。当我尝试在Raspberry PI上运行它时,我收到一条错误消息“没有模块命名请求”。如果我从语句末尾删除请求,则会加载该部分。然后我得到了另一个错误,如9所示:
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
我的代码如下:
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)