前提・実現したいこと
raspberry pi でカメラ自動撮影&自動送信アプリを作る
https://kazuhitogo.hateblo.jp/entry/2018/04/01/132423
上記のサイトさんの事をまるっきり同じことをしたいのですが
エラーが出てしまい質問させていただきました
発生している問題・エラーメッセージ
new mail(s) Traceback (most recent call last): File "app.py", line 80, in <module> cues = recieveGmail(server,username,password) File "app.py", line 64, in recieveGmail cue = cue.group(0).replace("<","").replace(">","") AttributeError: 'NoneType' object has no attribute 'group'
該当のソースコード
python
1 2# -*- coding: utf-8 -*- 3 4import os 5import sys 6import gmail 7from time import sleep 8 9import RPi.GPIO as GPIO 10from time import sleep 11import subprocess 12import datetime 13 14import imaplib, re, email, six 15 16# カメラ撮影関数 17def shotPicture(): 18 d = datetime.datetime.today() 19 filename = "{0}{1:02d}{2:02d}{3:02d}{4:02d}{5:02d}.jpg".format(d.year, d.month, d.day, d.hour, d.minute, d.second) 20 args = ['raspistill', '-o', filename, '-t', '1'] 21 subprocess.Popen(args) 22 return filename 23 24# メール送信 25def sendGmail(u,p,t,s,b,a): 26 #u=user,p=pass,t=to_addr,s=subject,b=body,a=attachment 27 client = gmail.GMail(u, p) 28 if a == '': 29 message = gmail.Message(s,to=t,text=b) 30 else: 31 message = gmail.Message(s,to=t,text=b,attachments=[a]) 32 client.send(message) 33 client.close() 34 35# メール受信 36def recieveGmail(s,u,p): 37 # s=server,u=username,p=password 38 client = imaplib.IMAP4_SSL(s) 39 client.login(u,p) 40 # 受信箱指定 41 client.select('INBOX') 42 # 未読メールをメモリに格納(この時点で既読になる) 43 typ, [data] = client.search(None, "(UNSEEN)") 44 45 # ない場合は空のcuesリストを返す 46 # 未読メールがあったか確認 47 cues = [] 48 if typ == "OK": 49 if data != b'': 50 print("new mail(s)") 51 # メールを一件ずつ処理 52 for num in data.split(): 53 result, d = client.fetch(num, "(RFC822)") 54 raw_email = d[0][1] 55 #文字コード取得用 56 msg = email.message_from_string(raw_email.decode('utf-8')) 57 fromObj = email.header.decode_header(msg.get('From')) 58 for f in fromObj: 59 cue = "" 60 if isinstance(f[0],bytes): 61 cue = f[0].decode('utf-8') 62 else: 63 cue = str(f[0]) 64 cue = re.search(r'<(.+)>',cue) 65 cue = cue.group(0).replace("<","").replace(">","") 66 cues.append(cue) 67 client.close() 68 client.logout() 69 return cues 70 71 72# gmail定義 73username = 'アカウント名@gmail.com' 74password = 'パスワード' 75server = 'imap.gmail.com' 76 77# 返信するホワイトリスト定義 78whitelist = ['返信する','パスワード','のリスト','hogehoge@gmail.com'] 79 80while True: 81 cues = recieveGmail(server,username,password) 82 cues = list(set(cues)) 83 if cues == []: 84 sleep(2) 85 else: 86 print(cues) 87 for addr in cues: 88 if addr in whitelist: 89 sendGmail(username,password,addr,'かしこまり','ちょっと待ってね','') 90 pictpass = shotPicture() 91 sleep(3) 92 sendGmail(username,password,addr,'はいどうぞ','いかが?',pictpass)
試したこと
AttributeError: 'NoneType' object has no attribute 'group'
の意味を調べたりしたのですが…