[질문]소스오류난곳좀 봐주세요 부탁드립니다.



  • 계속 여쭈어봐서 죄송합니다. 기존 계획과는다르게 소스가하나 있길래 돌려보려구 하는데 뭐가 문제인지 감이 잡히지를 않네요
    한번 봐주시겠어요? 이거는 지금 라즈베리파이에 드롭박스를 연동했습니다.
    그래서 적외선 센서에 신호가 뜨면 카메라로 찍은다음 dropbox에 사진을 올리려고 합니다.
    그리고 앱키는 받아서 123123 있는데에 입력을했고요 그런데도 오류가 뜨네요… 어떤게 잘못된건가요??

    #!/usr/bin/python
     
    import RPi.GPIO as GPIO
    import time
    import picamera
    import datetime
    import subprocess
    import dropbox
    import os
     
    # Get your app key and secret from the dropbox developer website
    app_key = '123123'
    app_secret = '123123r'
     
    def getFileName():
        return datetime.datetime.now().strftime("%Y-%m-%d_%H,%M,%S.h264")
     
    def dropboxAuth():
        accessTokenFileOverwrite = open("accessToken.txt", "w+")
        
        flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_seret)
        authorize_url = flow.start()
     
        # Have the user sign in and authorize this token
        authorize_url = flow.start()
        print '1. go to : ' + authorize_url
        print '2. click "Allow" (you might habe to log in first)'
        print '3. copy the authorization code here.'
        code = raw_input("Enter the aythorization code here: ").strip()
     
        try:
            # This will fail if the user enters an invaild authorization code
            access_token,  user_id = flow.finish(code)
            accessTokenFileOverwrite.write(access_token)
        except:
            print " failed authorization, restart"
            accessTokenFileOverwrite.close()
            os.remove("accessToken.txt")
     
        accessTokenFileOverwrite.close()
     
    def dropboxUpload(fileToUpload):
        if not os.path.isfile("accessToken.txt"):
            dropboxAuth()
     
        # get access token from file
        accessTokenFileRead = open("accessToken.txt", "r")
        access_token = accessTokenFileRead.read()
        accesTokenFileRead.close()
     
        # make client
        client = dropbox.client.DropboxClient(access_token)
        
        # upload file
        fileToUploadObject = open(fileToUpload, "rb")
        response = client.put_file(fileToUpload, fileToUploadObject)
        fileToUploadObject.close()
     
    sensorPin = 7
     
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(sensorPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
     
    prebState = False
    currState = False
     
    cam = picamera.PiCamera()
     
    while True:
        time.sleep(0.1)
        prevState = currState
        currState = GPIO.input(sensorPin)
        if currState !=prevState:
            newState = "HIGH" if currState else "LOW"
            print "GPIO pin %s is %s" % (sensorPin, newState)
            if currState:
                fileName = getFileName()
                print "Stating Recording..."
                cam.start_preview()
                cam.start_recording(fileName)
                print (filename)
            else:
                cam.stop_preview()
                cam.stop_recording()
                print "Stopped Recording"
                print "sending mail motification..."
                subprocess.call("mail -s 'Motion Detected' your@email.com.com< /home/pi/message.txt", shell=True)
                print "Complete"
                print "Uploading footage to Dropbox..."
                dropboxUpload(fileName)
                print "Complete"
    

    오류나는 부분은 제가 봤는데 전혀 이해가 안됍니다 ㅠㅠ 오류뜨면 이렇게 뜹니다.

    pi@raspberrypi ~ $ sudo python dropbox.py

    GPIO pin 7 is HIGH
    Stating Recording...
    Traceback (most recent call last):
      File "dropbox.py", line 8, in <module>
        import dropbox
      File "/home/pi/dropbox.py", line 81, in <module>
        print (filename)
    NameError: name 'filename' is not defined
    

    부탁드리겠습니다.!



  • @choihyeonsoo 파이썬은 들여쓰기를 해주시면 좋겠어요.


답글을 작성하기 위해 로그인
 

Rasplay Forum 사이트로의 연결이 끊어졌습니다. 다시 연결을 시도하는동안 잠시만 기다려 주십시오.