Bonjour,

Après de multiples essais pour faire tourner mon programme, je viens vous demander de l'aide.
Pour info j'ai un raspberry 3.
Quoique je fasse j'ai toujours ce message d'erreur:

pi@raspberrypi:~ $ ls
Alarmethomas.py Documents PIR_Alarm Templates python_games
Alarmethomas2.py Downloads Pictures Videos
Desktop Music Public alarmethomas3.py
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
pi@raspberrypi:~ $ sudo python alarmethomas3.py
  File "alarmethomas3.py", line 1
    Python 2.7.9 (default, Sep 17 2016, 20:26:04) 
             ^
SyntaxError: invalid syntax
pi@raspberrypi:~ $

Je vous joins mon programme parceque la je séche...
Par avance merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 
Python 2.7.9 (default, Sep 17 2016, 20:26:04) 
[GCC 4.9.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> 
>>> from email.MIMEBase import MIMEBase
from email.mime.image import MIMEImage
import os
from email omport Encoders
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import time
import datetime
import RPi.GPIO as GPIO
import picamera
import urllib
import urllib2
import sys
 
ntrusion :
Python
 
#envoi mail
def mail(message, f=None, f2=None):
  msg = MIMEMultipart()
  msg['From'] = 'cometeld@gmail.com'
  msg['To'] = 'cometeld@gmail.com'
  msg['Subject'] = 'Alerte intrusion'
  msg.attach(MIMEText(message))
  #fichier joint image
msg.attach(MIMEImage(file(f).read()))
 
#fichier joint video
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(f2).read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition','attachment; filename="%s"' % os.path.basename(f2))
msg.attach(part)
  mailserver = smtplib.SMTP('smtp.gmail.com',587) #ou un autre prestataire
  mailserver.ehlo() #non, il n'y a pas de faute de frappe
  mailserver.starttls()
  mailserver.ehlo()
  mailserver.login('cometeld@gmail.com', 'thomas')
  mailserver.sendmail('cometeld@gmail.com','cometeld@gmail.com',msg.as_string())
  mailserver.quit()
 
#SMS settings
#Replace the xxxxxxx with the number you wish to text.
to = "xxxxxxx"
#Replace the xxxxxx with the hash given to you by smspi.co.uk
hash = "xxxxx"
 
 
def sms(to,message,hash):
    values = {
          'to' : to,
          'message' : message,
          'hash' : hash } # Grab your hash from <a href="http://www.smspi.co.uk" target="_blank">http://www.smspi.co.uk</a>
 
    url = 'http://www.smspi.co.uk/send/'
 
    postdata = urllib.urlencode(values)
    req = urllib2.Request(url, postdata)
 
    print 'Attempt to send SMS ...'
 
    try:
      response = urllib2.urlopen(req)
      response_url = response.geturl()
      if response_url==url:
        print response.read()
    except urllib2.URLError, e:
      print 'Send failed!'
      print e.reason
 
 
GPIO.setmode(GPIO.BOARD)
 
pir = 7
 
GPIO.setup(pir, GPIO.IN)
camera = picamera.PiCamera()
while True:
    if GPIO.input(pir):
        a = datetime.datetime.now()
        a = str(a)
        a = a[0:19]
        alert = ("Alarm at "+str(a))
        print(alert)
        pic = (a)+(".jpg")
        vid = (a)+(".h264")
        message = (alert),(pic),(vid)
        camera.resolution = (1024, 768)
        camera.capture(pic)
        time.sleep(2)
        camera.resolution = (640, 480)
        camera.start_recording(vid)
        camera.wait_recording(10)
        camera.stop_recording()
        sms(to,message,hash)
        mail(alert,pic,vid)
        time.sleep(30)